How do I add to the beginning of an array and find the
number of elements in it?



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

Post New Answer

More PHP Interview Questions

What is print_r?

0 Answers  


how retrive the video file in php using video tag

0 Answers  


What is the difference between ereg_replace() and eregi_replace()?

2 Answers   Quicknet,


Explain what is the use of "echo" in php?

0 Answers  


if i give Limit for mysql query through php command line script like this for ex. $limit=500; $total_items = 1500; for($start=0;$start<$total_items;){ $command = "/usr/bin/php -q /home/sitename/public_html/admin/feedmanager/test.php feedid ".$_GET['feedid']." start ".$start." end ".$limit ; $start = $start+$limit; $command_result = system($command); } so it's execute command for 3 times so it give limit to sql query but if i have 27000 data so it takes long time? so my question is that is that any way from php command line script that i can use for collect all the data at once?

0 Answers  






why did u want to leave your past organisation?

0 Answers  


How can you propagate a session id?

0 Answers  


Where do we use get and post?

0 Answers  


Xplain is it possible to use com component in php?

0 Answers  


What is the difference between fopen() and fclose()?

0 Answers  


So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()?

0 Answers  


What is difference between static and constant in php?

0 Answers  


Categories