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'
)
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.
the dollar sign appears before a variable/array. Essentially it just tells php that its a variable. $food = "cheese pizza"; or $myfavoritenumber = 2 ;
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 ?>
In the declaration of the receiving function, you add an ampersand. <?php function myWayCoolFunction( &$params) {.....} $x = array('1','2','3'); myWayCoolFunction($x) ?>
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.
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.
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
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 ?>
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 ?>
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).
displaying a variable in php using echo statement? <?php $name="ram"; //declaring and defining the variable echo "$name"; //printing the variable using echo command ?>
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 ?>