How do I add to the beginning of an array and find the
number of elements in it?
Answer Posted / 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 |
Post New Answer View All Answers
How to redirect a url from http to https in .htaccess?
What is the difference between super () and this ()?
How to check a key exist in an array?
What is the super method?
What can php do?
How we get ip address of client, previous reference page etc?
What function should you use to join array elements with a glue string?
What is difference between php and wordpress?
Do you know what is the difference between mysql_fetch_object() and mysql_fetch_array()?
How to define a function with any number of arguments?
Explain what is meant by pear in php?
Tell me what is the difference between characters 34 and x34?
How can cross site request forgery csrf be prevented?
What is a stored procedure in mysql?
What is asort php?