how to pop an element off ANYWHERE in an array?

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
Deseree
Forum Commoner
Posts: 84
Joined: Mon Feb 13, 2006 11:35 pm

how to pop an element off ANYWHERE in an array?

Post by Deseree »

http://us3.php.net/manual/en/ref.array.php

I see array_pop() but that only does it for the last element of an array.

I am going through an array like this:

Code: Select all

for($kount=0;$kount<sizeof($ps_list);$kount++)
						{
							$pxy = explode("|",$ps_list[$kount]);
							$pxy = $pxy[0];
								
							if($pxy[$kount] == $this->C_PS)
							{
								$ps_list[$kount] = "";
						

							}
						}
And $this->C_PS is the element of an array I need to pop. This so far removes it from the .txt file but not from the array..... Any ideas how I would remove this element from the array? unset() I'm guessing that wont' work?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

array_splice() or array_slice()
unset() works too if you don't want what was in the element(s) you remove.
Deseree
Forum Commoner
Posts: 84
Joined: Mon Feb 13, 2006 11:35 pm

Post by Deseree »

thanks/sorry bout double post accident.
Deseree
Forum Commoner
Posts: 84
Joined: Mon Feb 13, 2006 11:35 pm

Post by Deseree »

mmk, I definately don't want what was in the element of the array, but another part of my script/function is transfeversing the array by using current() and next(), and also reset() , will it be a problem if I use unset on this SINGLE element, when it resets and comes back to this element, will it show up as blank, or does unset remove the KEY and the VALUE from the array, so when it comes back around with current() and next(), it will just SKIP to the next position automatically, or will i need to resort somehow ( maintaining current order of course)?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

current(), next(), reset(), and rewind() are not affected by unset() when it is run prior. I haven't tested unset() during their usage.
Deseree
Forum Commoner
Posts: 84
Joined: Mon Feb 13, 2006 11:35 pm

Post by Deseree »

bummer, didnt work.

I can't use array splice or array slice since I don't have the position, unless array_keys() returns that... let me try that...
Post Reply