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
)
Comment on this Question and Answer >>>
ASK A QUESTION
More arrays PHP Questions
How do I reverse the order of the elements in an array?How can I display values in a two dimensional array?
How do I remove and view the last element of an array?
I'm shuffeling through numbers range(1, 10). Can I eval resulting random numbers and convert to appropriate text? 1 = username1, 2 = username2...etc?
How do I return all the values in an array?
