I have an PHP array that looks something like this:
Index Key Value
[0] 1 Awaiting for Confirmation
[1] 2 Assigned
[2] 3 In Progress
[3] 4 Completed
[4] 5 Mark As Spam
When I var_dump the array values i get this:
array(5) { [0]=> array(2) { ["key"]=> string(1) "1" ["value"]=> string(25) "Awaiting for Confirmation" } [1]=> array(2) { ["key"]=> string(1) "2" ["value"]=> string(9) "Assigned" } [2]=> array(2) { ["key"]=> string(1) "3" ["value"]=> string(11) "In Progress" } [3]=> array(2) { ["key"]=> string(1) "4" ["value"]=> string(9) "Completed" } [4]=> array(2) { ["key"]=> string(1) "5" ["value"]=> string(12) "Mark As Spam" } }
I wanted to remove Completed and Mark As Spam. I know I can unset[$array[3],$array[4])
, but the problem is that sometimes the index number can be different.
Is there a way to remove them by matching the value name instead of the key value?
Your array is quite strange : why not just use the
key
as index, and thevalue
as... the value ?Wouldn't it be a lot easier if your array was declared like this :
That would allow you to use your values of
key
as indexes to access the array...And you'd be able to use functions to search on the values, such as
array_search()
:Easier than with your array, no ?
Instead, with your array that looks like this :
You'll have to loop over all items, to analyse the
value
, and unset the right items :Even if do-able, it's not that simple... and I insist : can you not change the format of your array, to work with a simpler key/value system ?