Req #12129 [Com]: array_remove()

2012-08-30 Thread KayL at cust dot in
Edit report at https://bugs.php.net/bug.php?id=12129&edit=1

 ID: 12129
 Comment by: KayL at cust dot in
 Reported by:dmertens at zyprexia dot com
 Summary:array_remove()
 Status: Not a bug
 Type:   Feature/Change Request
 Package:Feature/Change Request
 Operating System:   Linux
 PHP Version:4.0.6
 Block user comment: N
 Private report: N

 New Comment:

No it is not.
What if I do not know the key, but want to delete exactly that array element?


Examples:
-
$needle = "foo";
$hackstack = Array("foo"=>"bar", 0=>"red", "would be"=>"cool");
array_remove($needle, $hackstack) = Array(0=>"red", "would be"=>"cool");

$needle = Array("would be", 0);
$hackstack = Array("foo"=>"bar", 0=>"red", "would be"=>"cool");
array_remove($needle, $hackstack) = Array("foo"=>"bar");


Function:
-
function array_remove(mixed $needle, Array $hackstack)
{
if(empty($hackstack)) return Array();

$new_array = Array();
foreach($hackstack as $key=>$value)
{
if($value != $needle)
{
$new_array[$key] = $value;
}
}
return $new_array;
}


Previous Comments:

[2001-07-13 03:44:41] z...@php.net

Thank you for the suggestion! However this functionality is already part of PHP.

Use:
   unset ($array['key']);


[2001-07-13 03:21:58] dmertens at zyprexia dot com

I would like to see an function called array_remove(needle, haystack) with 
removes an item from an associative (or indexed) array.

Currently i have a workaround which loops the array. During the loop a new 
array is created. When the loop finds the item which has to be removed, it skip 
the current item.

After the loop, the new array is returned. A function like this would complete 
the array functions.

Dave Mertens
dmert...@zyprexia.com





-- 
Edit this bug report at https://bugs.php.net/bug.php?id=12129&edit=1


Req #12129 [Com]: array_remove()

2012-08-30 Thread KayL at cust dot in
Edit report at https://bugs.php.net/bug.php?id=12129&edit=1

 ID: 12129
 Comment by: KayL at cust dot in
 Reported by:dmertens at zyprexia dot com
 Summary:array_remove()
 Status: Not a bug
 Type:   Feature/Change Request
 Package:Feature/Change Request
 Operating System:   Linux
 PHP Version:4.0.6
 Block user comment: N
 Private report: N

 New Comment:

Fcuk. Ofc I meant:


$needle = "bar";
$hackstack = Array("foo"=>"bar", 0=>"red", "would be"=>"cool");
array_remove($needle, $hackstack) = Array(0=>"red", "would be"=>"cool");

$needle = Array("cool", 0xB16B00B5);
$hackstack = Array("foo"=>"bar", 8=>0xB16B00B5, "would be"=>"cool");
array_remove($needle, $hackstack) = Array("foo"=>"bar");


Previous Comments:

[2012-08-30 19:14:31] KayL at cust dot in

No it is not.
What if I do not know the key, but want to delete exactly that array element?


Examples:
-
$needle = "foo";
$hackstack = Array("foo"=>"bar", 0=>"red", "would be"=>"cool");
array_remove($needle, $hackstack) = Array(0=>"red", "would be"=>"cool");

$needle = Array("would be", 0);
$hackstack = Array("foo"=>"bar", 0=>"red", "would be"=>"cool");
array_remove($needle, $hackstack) = Array("foo"=>"bar");


Function:
-
function array_remove(mixed $needle, Array $hackstack)
{
if(empty($hackstack)) return Array();

$new_array = Array();
foreach($hackstack as $key=>$value)
{
if($value != $needle)
{
$new_array[$key] = $value;
}
}
return $new_array;
}


[2001-07-13 03:44:41] z...@php.net

Thank you for the suggestion! However this functionality is already part of PHP.

Use:
   unset ($array['key']);


[2001-07-13 03:21:58] dmertens at zyprexia dot com

I would like to see an function called array_remove(needle, haystack) with 
removes an item from an associative (or indexed) array.

Currently i have a workaround which loops the array. During the loop a new 
array is created. When the loop finds the item which has to be removed, it skip 
the current item.

After the loop, the new array is returned. A function like this would complete 
the array functions.

Dave Mertens
dmert...@zyprexia.com





-- 
Edit this bug report at https://bugs.php.net/bug.php?id=12129&edit=1


[PHP-BUG] Req #62979 [NEW]: Re-Request of additional function "array_remove($needle, $haystack)""

2012-08-30 Thread KayL at cust dot in
From: KayL at cust dot in
Operating system: All
PHP version:  5.4.6
Package:  Arrays related
Bug Type: Feature/Change Request
Bug description:Re-Request of additional function "array_remove($needle, 
$haystack)""

Description:

I'd like to re-request the function
  array_remove($needle, $haystack);
for the deletion of one/multiple array element/s from an existing array.

Similar to Bug #12129 (by Dave Mertens), but:


(zak) "[...]
   Use: unset($array['key']);"

(Kay) "What if I do not know the key, but still want to delete every
occurrence of array elements where
   only the value - not key - is known (and of course keeping the
original arrays order)?.
   This would - in my opinion as well as Mr. Mertens' - complete the
native functions for arrays."


Example-Input:
--
$needle = "red";
$haystack = Array("foo"=>"bar", 0=>"red", "would"=>"be cool");
array_remove($needle, $haystack) --> Array("foo"=>"bar", "would"=>"be
cool");

$needle = Array("be cool", 0xB16B00B5);
$haystack = Array("foo"=>"bar", 8=>0xB16B00B5, "would"=>"be cool");
array_remove($needle, $haystack) --> Array("foo"=>"bar");


My sample function (or this request for that matter) may not be perfect.
But please be kind - it's 01:15 AM in Germany and I have to get up for work
in about 5 hours...
 

Test script:
---
function array_remove($needle, Array $hackstack)
{
if(empty($hackstack)) return Array();
if(!is_array($needle) && !is_string($needle) &&
   !is_numeric($needle)) return $hackstack;

$new_array = Array();
foreach($hackstack as $key=>$value)
{
if(is_array($needle))
{
$found = FALSE;
foreach($needle as $needle2)
{
if((string)$needle2 == (string)$value)
$found = TRUE;
}
if(!$found) $new_array[$key] = $value;
}
else
{
if((string)$needle != (string)$value)
$new_array[$key] = $value;
}
}

return $new_array;
}


-- 
Edit bug report at https://bugs.php.net/bug.php?id=62979&edit=1
-- 
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=62979&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=62979&r=trysnapshot53
Try a snapshot (trunk):  
https://bugs.php.net/fix.php?id=62979&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=62979&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=62979&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=62979&r=alreadyfixed
Need backtrace:  
https://bugs.php.net/fix.php?id=62979&r=needtrace
Need Reproduce Script:   
https://bugs.php.net/fix.php?id=62979&r=needscript
Try newer version:   
https://bugs.php.net/fix.php?id=62979&r=oldversion
Not developer issue: 
https://bugs.php.net/fix.php?id=62979&r=support
Expected behavior:   
https://bugs.php.net/fix.php?id=62979&r=notwrong
Not enough info: 
https://bugs.php.net/fix.php?id=62979&r=notenoughinfo
Submitted twice: 
https://bugs.php.net/fix.php?id=62979&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=62979&r=globals
PHP 4 support discontinued:  
https://bugs.php.net/fix.php?id=62979&r=php4
Daylight Savings:https://bugs.php.net/fix.php?id=62979&r=dst
IIS Stability:   
https://bugs.php.net/fix.php?id=62979&r=isapi
Install GNU Sed: 
https://bugs.php.net/fix.php?id=62979&r=gnused
Floating point limitations:  
https://bugs.php.net/fix.php?id=62979&r=float
No Zend Extensions:  
https://bugs.php.net/fix.php?id=62979&r=nozend
MySQL Configuration Error:   
https://bugs.php.net/fix.php?id=62979&r=mysqlcfg