On 4/10/07, Richard Lynch <ceo@xxxxxxxxx> wrote:
http://php.net/array_flip followed up an unset, followed by another array_flip, I guess...
What if you have an array like this: Array ( [0] => Array ( [0] => 1 [1] => 2 [2] => 2 [3] => 2 [4] => 2 [5] => 4 ) [1] => 4 [2] => 2 [3] => 4 ) And i want to remove the 4, but i don't know 1 and 3. using array_flip wouldn't work because of my multi-dimensional array. But what if i'm using array_search? will it return 1 only? will it return 5?
Why in the world you'd architect the array with a value when you need to unset by value in the first place is beyond me, though...
Sometimes you end up with such arrays, where you need to have non-unique values first, so you store them in the value, and then you need to remove some of the non-unique values. But it's a multi-dimensional array... Tijnema
On Tue, April 10, 2007 2:52 pm, Tijnema ! wrote: > On 4/10/07, Richard Lynch <ceo@xxxxxxxxx> wrote: >> http://php.net/unset > > That works when you know the key, but will that work when you only > know the value? > > Tijnema >> >> >> On Tue, April 10, 2007 2:49 pm, Tijnema ! wrote: >> > Hi, >> > >> > Is there currently a function that removes a key/value from an >> array? >> > I use this code right now: >> > function array_remove($array,$remove,$remove_value = true) >> > { >> > foreach($array as $key => $value) { >> > if($remove_value && $value != $remove) { >> > $new_array[$key] = $value; >> > } elseif (!$remove_value && $key != $remove) { >> > $new_array[$key] = $value; >> > } >> > } >> > return $new_array; >> > } >> > >> > array_remove(array(1=>2,2=>3),2,true); // array (2=>3) >> > array_remove(array(1=>2,2=>3),2,false); // array (1=>2) >> > >> > Anyone knows if there already exists such function? >> > >> > Else should i create future request? >> > >> > Tijnema >> > >> > -- >> > PHP General Mailing List (http://www.php.net/) >> > To unsubscribe, visit: http://www.php.net/unsub.php >> > >> > >> >> >> -- >> Some people have a "gift" link here. >> Know what I want? >> I want you to buy a CD from some indie artist. >> http://cdbaby.com/browse/from/lynch >> Yeah, I get a buck. So? >> >> > -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php