Re: Poping array which has the matching value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Leo Liu wrote:
> Hi,
> 
> I wanted to search through the array and pop out the value which match my search criteria. For example
> 
> If array has {a,b,c,d,e,f}
> 
> I wanna search for "c" and once I found it, took it out from the array.

here is a 'solution', you may not understand it fully - in which case the manual
is your best friend - he has unlimited patience when explaining and he is a very
gifted teacher (he managed to knock this stuff into my thick skull ;-)

$haystack = range("a","f");
$needle   = "c";
while (($key = array_search($needle, $haystack, true)) !== false)
	unset($haystack[$key]);

$haystack = array_values($haystack);

> 
> So the result of the array after operation will be
> 
> {a,b,d,e,f}
> 
> If I do array_pop(); function it will only pop the last element inside the array and the array will become
> 
> {a,b,c,d,e}
> 
> Anyway to search the desire element inside the array and took it out from the array?
> 
> Regards,
> Leo
>  
> Reality starts with Dream

No It Does Not. Reality is what becomes apparent when you you stop judging,
stop thinking and stop dreaming. That being so we're all sound asleep.

now I'm back off to dreaming about swedish triplets driving around in an Audi RS4. :-P

> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux