How do I add to the beginning of an array and find the
number of elements in it?
Answer / jude jeevanraj.p
To do this, you will want to use the array_unshift function
which works like this.
<?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
)
| Is This Answer Correct ? | 8 Yes | 0 No |
Tell me how can we change the maximum size of the files to be uploaded?
What is php trait?
How can you parse files that were not ending with .php by using Apache?
How to find current date and time?
What are the advantages of stored procedures, triggers, indexes in php?
Can the value of a constant change during the script's execution?
What are the benefits of using queries?
Explain the types of string comparision function in PHP
How would you open a directory for reading in php?
What is == and === in php?
What is a class in php programing?
What is the difference between php 5 and php 7?