Ho questa matrice:PHP cancellare sub-array da array multidimensionale da sub-array valore chiave
array(5) {
[0]=>
array(4) {
["nachricht"]=>
string(9) "blablaaaa"
["user"]=>
string(15) "334607943355808"
["datum"]=>
string(16) "18.09.2014 11:13"
["deleted"]=>
string(0) ""
}
[1]=>
array(4) {
["nachricht"]=>
string(3) "joo"
["user"]=>
string(15) "334607943355808"
["datum"]=>
string(16) "18.09.2014 11:56"
["deleted"]=>
string(15) "334607943355808"
}
[2]=>
array(4) {
["nachricht"]=>
string(4) "noma"
["user"]=>
string(15) "334607943355808"
["datum"]=>
string(16) "18.09.2014 11:56"
["deleted"]=>
string(0) ""
}
[3]=>
array(4) {
["nachricht"]=>
string(4) "test"
["user"]=>
string(15) "334607943355808"
["datum"]=>
string(16) "18.09.2014 11:56"
["deleted"]=>
string(0) ""
}
[4]=>
array(4) {
["nachricht"]=>
string(4) "doh!"
["user"]=>
string(15) "334607943355808"
["datum"]=>
string(16) "18.09.2014 11:56"
["deleted"]=>
string(0) ""
}
}
voglio cancellare tutti i sub-array che comprendono il valore 334.607.943.355.808 nella chiave "eliminata" in il sottoarray. Ho ottenuto questo codice:
if(($key = array_search("334607943355808", $array)) !== false) {
unset($array[$key]);
}
da: PHP array delete by value (not key) dove è non multi-array, ma come posso farlo nel mio caso?
EDIT:
Ho provato in questo modo la società:
foreach($array as $delete){
if(($key = array_search("334607943355808", $delete)) !== false) {
unset($delete[$key]);
}
}
ma non sta lavorando
è necessario ricorsione. –
Utilizzare un ciclo foreach nidificato e controllare i valori per vedere se contengono il proprio numero? – TheOneWhoSighs
non è flessibile, ma in questo caso funzionerà altrettanto bene. –