Array Shift

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ek5932
Forum Commoner
Posts: 25
Joined: Mon Jun 28, 2004 5:55 pm

Array Shift

Post by ek5932 »

Hi, I have been browsing through the PHP website and I am not quite sure why this dosnt work. I am trying to shift my array and then add a 0 on the end. the code I have is:

Code: Select all

$unpack = explode("|",$row[$type[$counter][name]]);
$unpack = array_shift($unpack);
$unpack[] = 0;
array shift dosn't actually shift the array it just displays the first value in the array. any help would be great, thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you're "destroying" $unpack when you set it from array_shift(). array_shift() does shift the array, the array passed to it and returns the element shifted out of the array.
Post Reply