Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Explain me what is the use of 'print' in php?

880


Why does sql injection happen?

948


Why is php used?

976


How to replace a substring in a given string in php?

995


Explain what does the expression exception::__tostring means?

827


What is meant by session in php?

892


How to access a global variable inside a function?

952


How can i execute PHP File using Command Line?

934


Explain what is the main difference between require() and require_once()?

942


Tell me what does the scope of variables means?

899


Tell me how comfortable are you with writing html entirely by hand?

871


What is the purpose of break and continue statement?

927


What is xss and csrf?

876


What does empty mean in php?

932


Does php pass arrays by reference?

1036