rfc:array_delete
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:array_delete [2012/08/22 18:41] – [Answer to criticism] yohgaki | rfc:array_delete [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2012-08-21 | * Date: 2012-08-21 | ||
* Author: | * Author: | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
===== Introduction ===== | ===== Introduction ===== | ||
Line 47: | Line 47: | ||
To prevent accidental deletion, $strict defaults to true - note that this differs from array_search() where the most likely objective is to "find something" | To prevent accidental deletion, $strict defaults to true - note that this differs from array_search() where the most likely objective is to "find something" | ||
+ | |||
+ | Above example is inefficient, | ||
+ | |||
+ | <code php> | ||
+ | function array_delete(& | ||
+ | $count = 0; | ||
+ | array_walk($array, | ||
+ | if ($strict) { | ||
+ | if ($item === $value) { | ||
+ | $count++; | ||
+ | unset($array[$key]); | ||
+ | } | ||
+ | } else { | ||
+ | if ($item == $value) { | ||
+ | $count++; | ||
+ | unset($array[$key]); | ||
+ | } | ||
+ | } | ||
+ | }; | ||
+ | return $count; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Note for non internal programmers: | ||
<code php>int array_delete_recursive(& | <code php>int array_delete_recursive(& | ||
Line 116: | Line 140: | ||
It says so [[http:// | It says so [[http:// | ||
+ | |||
+ | === Please add this === | ||
+ | |||
+ | I was needing something exactly like this! | ||
== Deleting CURRENTLY working element is OK == | == Deleting CURRENTLY working element is OK == |
rfc/array_delete.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1