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 are soundex() and metaphone() functions in php?

0 Answers  


How error handling is being handled by php?

0 Answers  


What are the methods of array in java?

0 Answers  


What is the correct and the most two common way to start and finish a php block of code?

0 Answers  


How do you match the character ^ at the beginning of the string? - ^^

1 Answers  






we store and display scores of users in different games. In MySQL, records are stored as tuples (user-id, game-id, score). Now we need to support ranks of users, i.e., each user should be informed of his current rank in the community. The challenge is to come up with the best way to store the data in MySQL so that the requirements are efficiently met.

1 Answers   IndiaTimes,


Explain the syntax for ‘foreach’ loop with example.

0 Answers  


In php how can you jump in to and out of "php mode"?

0 Answers  


how to upload more than 50 mb? i tried but session was expired....certain time .....i was set session duration three days .... how to rectified? if any one know that post ur answer as soon as possible?already i was increase php.ini and set Also increase Memory_limit Post_max_size upload_max_filesize..........but not working......

0 Answers  


Which php framework is fastest?

0 Answers  


What is the purpose of the following files having extensions: frm, myd, and myi? What these files contain?

0 Answers  


Tell me what sized websites have you worked on in the past?

0 Answers  


Categories