answersLogoWhite

0

How do you append post variable in an array in php?

Updated: 8/20/2019
User Avatar

Wiki User

11y ago

Best Answer

The $_POST variable is an array already, so if you want to append it to another array, you can use the array_merge function to do so. For example:

$foo = array('alpha', 'bravo', 'charlie');
$bar = array_merge($foo, $_POST);

If there were two variables posted, one called "blah" with a value of 7 and one called "snarf" with a value of "snoo", then the $bar array would now be:

Array(
0 => 'alpha',
1 => 'bravo',
2 => 'charlie',
'blah' => 7,
'snarf' => 'snoo'
)

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you append post variable in an array in php?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What symbol denotes a variable in php?

The money sine ($) denotes a variable in PHP; for example: $var = 'foobar'; It can also be used to reference an array, object, any of the othe typical things that can be assigned to a variable.


What is the Use of a dollar sign in php?

the dollar sign appears before a variable/array. Essentially it just tells php that its a variable. $food = "cheese pizza"; or $myfavoritenumber = 2 ;


How do you empty an array in PHP?

To empty an array in PHP you need to use the unset function like shown below: <?php $array = array('hello', 'hi', 'weee'); unset($array); // empty ?>


How do you pass a variable by value in php?

In the declaration of the receiving function, you add an ampersand. <?php function myWayCoolFunction( &$params) {.....} $x = array('1','2','3'); myWayCoolFunction($x) ?>


What is the difference between an array shift and unsetting a variable in PHP?

By shifting the values in an array, you are moving a key's value to the previous key. The very first key's value is obliterated. By shifting all values in the array, all keys will have a value of NULL. Unsetting a variable is entirely different -- performing a variable unsetting causes the variable to have a value of NULL, as if it was never set.


What is the difference between POST and REQUEST methods in PHP?

The $_POST array contains only variables supplied by a form that used the POST method, while the $_REQUEST array combines the $_POST, $_GET and $COOKIE arrays.


How do you sort variable in ascending or descending order both in php?

Assuming that the values are stored in an array, you can use the php function sort($array) to sort ascending, and rsort to sort descending. The following link gives a table that lists all of the built in PHP sort functions: http://php.net/manual/en/array.sorting.php


How can you mix up the order of values in a PHP array?

To shuffle an array in PHP is easy to do, all you need to use is the shuffle() function like shown below: <?php $array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); shuffle($array); // array results will be randomly shuffled ?>


How do you find the size of an array in PHP?

To find the size of an array in PHP you can either use the count() function or the sizeof() function as they will produce the same result. <?php $array = array(1, 2, 3, 4, 5, 6, 7); echo count($array); // outputs 7 echo sizeof($array); // outputs 7 ?>


What is difference between key and index in php arrays?

A key is the name of a variable in an array ($array["key"]) and the index is the position it's at ($array = ["key" => 0], the index would be 0). Keys and indices are the same if the array is not associative though ($array = [true], the key holding the value true is named 0 and is at index 0).


How to display a variable in PHP using echo or print statements?

displaying a variable in php using echo statement? <?php $name="ram"; //declaring and defining the variable echo "$name"; //printing the variable using echo command ?>


How do you pick a random value from a PHP array?

To pick random results from an array in PHP you will need to use the array_rand() function, you can select the amount of results you wish it too select too. <?php $array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); $rand_results = array_rand($array, 3); // will select 3 random results from the array and store in a new array ?>