How do I add to the beginning of an array and find the number of elements in it?
<?php
$values = array(2,3,4,5,6,7,8,9,10);
$elements = array_unshift($values,1);
echo "Number of elements: $elements \n\n";
print_r($values);
?>
Here's the output:
Number of elements: 10
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 7
[7] => 8
[8] => 9
[9] => 10
)
More arrays PHP Questions
How can I reset an array in PHP?How can I create an array of numbers easily?
How do I remove the first element from an array?
How do I reverse sort an array by key?
How can I mix up the order of values in an array?