Home PHP How to get the first element of an array using PHP?
 
 
 

How to get the first element of an array using PHP?

PDF Print E-mail

Question: How to get the first element of an array using PHP?

 

If you have the array

$array = array('a','b','c','d');
you will need to get the value a from the array

 

Answer:

Use the array_shift function available in PHP 4 and 5 which shifts an element off the beginning of an array. See example below

$array = array('a','b','c','d');
$first_element = array_shift($array);
echo $first_element;
The above code will output a

 

+/-
+/- Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
Security Please input the anti-spam code that you can read in the image.
 

Go Daddy $7.49 .com Sale!