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 |
Hi, My Name is Ajay Jha. What My Question is I am Percuing in Bca. It's My 5th Semester. I Want To Make My Carrear as a web designer that's Why i wants to do Php, Is it right Desision for Me ?
What are the difference between abstract class and interface in oops?
Is runtime polymorphism overriding?
What are the variables in php?
How to read the entire file into a single string?
Explain me what are the 3 scope levels available in php and how would you define them?
Is it possible multiple inheritance in php?
What is the use of imagetypes() method?
What the limitation of header() function in php?
Tell me how is it possible to return a value from a function?
What is php built on?
Is polymorphism inherited?