In the declaration of the receiving function, you add an ampersand. <?php function myWayCoolFunction( &$params) {.....} $x = array('1','2','3'); myWayCoolFunction($x) ?>
the dollar sign appears before a variable/array. Essentially it just tells php that its a variable. $food = "cheese pizza"; or $myfavoritenumber = 2 ;
To merge arrays in PHP all you have to do is use the array_merge() function like shown below: <?php $array1 = array("Matt", "Michael", "Justin"); $array2 = array("Janice", "Janet", "Kylie"); $array3 = array_merge($array1, $array2); ?> One thing to remember when merging arrays is you might be creating duplicate results, if you don't want 2 or more of the same result in the array remember to use the function array_unique() to remove the duplicate results from it!
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).
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.
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 ?>
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 ?>
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 ?>
To reverse the results in a PHP array is really simple, all you need to do is use the array_reverse() function like shown below: <?php $my_array = array(1, 2, 3); $reverse_me = array_reverse($my_array); // will be stored as 3, 2, 1 now ?>
$foo = array(1.41421356, 1.61803399, 2.71828183, 3.14159265);
To separate a sentence into an array of words, you can use PHP's explode() function. If $text is your sentence, then use the following: $result = explode(" ", $text);
build an array of vowels then do a foreach on the array and then explode the string on the array value and the answer is -1 of the result
To check if a value is already in an array you will need to use the in_array function like shown below! <?php $values = array("pizza","hello","cheese","fred"); $newvalue = "hello"; if (in_array($newvalue, $values)) { echo "$newvalue is already in the array!"; } ?>
Using the function "count". <?php $foo = array("John", "Jacob", "Jingleheimer", "Schmidt"); echo count($foo); // <-- outputs the number 4 ?>
Use a for-loop starting at the length of the array and go backwards and build up a new array with the values.
Yes, PHP and C both do.