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 |
What is the static variable in function useful for?
What is the Default syntax used in PHP?
How can we enable error reporting in php?
What are the differences between mysqli_connect and mysqli_pconnect?
Explain what is smarty?
What is the alternative structure for control structures?
What and How possible injection in PHP and mysql?
Why session is required?
Tell me how do you execute a php script from the command line?
What is the use of super-global arrays in php?
How do I get csrf token?
How can you send http header to the client in php?