Mark Forums Read
  #1  
Old 02-19-2009, 09:03 AM
steve.callen steve.callen is offline
Junior Member
 
Join Date: Feb 2009
Posts: 1
steve.callen is on a distinguished road
Default How do I remove the first element from an array?

hi all,

Please tell me how do I remove the first element from an array?

Thanks
Reply With Quote
 #Add to Ads's Reputation  
OldSponsored Ads
Ads AdsPromoter is online
Member
 
Join Date: LongTime
Posts: 1100
Ads is on a distinguished road
Default New Sponsored Ads



This message will go away once you are registered. Also, by registering, you will have access to all post topics, communicate privately with other members (PM), respond to polls, upload graphics, and access other special features! Registration is fast, simple and absolutely free so please Click Here to join our Web Hosting community today!
Reply With Quote
  #2  
Old 03-19-2009, 12:19 PM
vks87 vks87 is offline
Member
 
Join Date: Mar 2009
Posts: 85
vks87 is on a distinguished road
Default

Try this.Hope it ll work well.
Code:
array_shift()
Reply With Quote
  #3  
Old 07-16-2009, 07:38 AM
gkumar gkumar is offline
Senior Member
 
Join Date: Jun 2009
Posts: 203
gkumar is on a distinguished road
Default How do I remove the first element from an array?

Often with an array the key of the first element in the array won't simply be '0'.

Often you want to add or remove values from the start or end of an array. To remove the first value in the array and see what it is, you can use the array_shift function in PHP:
Quote:
<?php
$values = array(1,2,3,4,5,6,7,8,9,10);
$first = array_shift($values);
echo "First value was: $first";
print_r($values);
?>

Which tells us this:

First value was: 1

Array
(
[0] => 2
[1] => 3
[2] => 4
[3] => 5
[4] => 6
[5] => 7
[6] => 8
[7] => 9
[8] => 10
Notice how the keys get re-assigned after the call to array_shift, so that '2' now has a key of zero whereas in the initial array that key referenced the number '1' which has now been removed from the array.
Reply With Quote
  #4  
Old 08-11-2011, 06:54 AM
peterjack15 peterjack15 is offline
Senior Member
 
Join Date: Aug 2011
Posts: 146
peterjack15 is on a distinguished road
Default

Often with an array the key of the first element in the array won't simply be '0'.
Reply With Quote
  #5  
Old 12-01-2011, 08:10 AM
donaldpeter58 donaldpeter58 is offline
Junior Member
 
Join Date: Dec 2011
Posts: 5
donaldpeter58 is on a distinguished road
Default

Notice how the keys get re-assigned after the call to array_shift, so that '2' now has a key of zero whereas in the initial array that key referenced the number '1' which has now been removed from the array.
__________________
r4
Reply With Quote
 #Add to Ads's Reputation  
OldSponsored Ads
Ads AdsPromoter is online
Member
 
Join Date: LongTime
Posts: 1100
Ads is on a distinguished road
Default New Sponsored Ads



This message will go away once you are registered. Also, by registering, you will have access to all post topics, communicate privately with other members (PM), respond to polls, upload graphics, and access other special features! Registration is fast, simple and absolutely free so please Click Here to join our Web Hosting community today!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 01:43 AM.


Powered by vBulletin Version 3.6.1
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 2.4.0