PHP Remove key from associative array -
I have a PHP array that looks like this:
index key value [0 ] 1 Waiting for confirmation [1] 2 constituted [2] 3 in progress [3] 4 full [4] 5 Mark as spam When I assume the var_dump array So I get this: / P>
array (5) {[0] => Array (2) {["key"] = & gt; String (1) "1" ["value"] = & gt; String (25) "Waiting for confirmation"} [1] = & gt; Array (2) {["key"] = & gt; String (1) "2" ["value"] = & gt; String (9) "Assigned"} [2] = & gt; Array (2) {["key"] = & gt; String (1) "3" ["value"] = & gt; String (11) "in progress"} [3] = & gt; Array (2) {["key"] = & gt; String (1) "4" ["value"] = & gt; String (9) "full"} [4] = & gt; Array (2) {["key"] = & gt; String (1) "5" ["value"] = & gt; I wanted to remove "marked" as "full" and "marked as spam"; I know that I [$ array [3], mark it as "spam" $ Array [4]) but the problem is that the index number may be different for some time, hence there is a way to remove "full" and "spam like mark" by matching the value to the name? Thank you very early
Your array is quite strange: Why not Use the key as the index only, and the value as the value ? If your array was declared this way then it would not be so easy:
$ array = array (1 = & gt; Waiting ', 2 = & gt;' Assdigned ', 3 = & gt; in Progress', 4 = & gt;' Full ', 5 = & gt; as Spam'); This will allow you to use your values of the key as indexed to use the array ... And you will be able to use the function to find values such as:
$ indexCompleted = array_search ('full', $ array); Not set ($ array [$ indexCompleted]); $ Index Spam = array_search ('mark as spam', $ array); Not set ($ array [$ indexSpam]); Var_dump ($ array); Instead, with its array that looks like this: (' Key '= & gt; 2,' value '=' Gtc: mediafile = 'gt; & gt; ASACEED), array (' key '=> 3,' value '= & gt; in progress '), Array (' key '= & gt; 4,' value '= & gt;' complete '), array (' key '=> 5,' value '= & gt;' 'marked as spam Do '),); To analyze you and to unset the right items, you must loop over all items:
foreach ( $ Index = & gt; $ array as data $] {if ($ data ['value'] == 'full' || $ data ['value'] == 'mark as spam') {unset ($ Array [$ index]); }} Var_dump ($ array); Even if enabled, this is not easy ... and I urge: can not you change the format of your array to work with simple array / value system ?
Comments
Post a Comment