Ho una grande matrice multidimensionale. E devo trovare sotto-array specifico da esso.
Ho provato a utilizzare una funzione di ricorsione ma in realtà non restituisce valori. Qualcuno può darmi un'altra soluzione.
Ecco l'anteprima della matrice.ricava un valore specifico dall'array multidimensionale
Array
(
[0] => Array
(
[expanded] => 1
[key] => _1
[title] => New
)
[1] => Array
(
[key] => _2
[title] => Home
)
[2] => Array
(
[expanded] => 1
[key] => _3
[title] => Care
[children] => Array
(
[0] => Array
(
[expanded] => 1
[key] => _4
[title] => face
[children] => Array
(
[0] => Array
(
[key] => _5
[title] => new
)
[1] => Array
(
[key] => _6
[title] => <strong>face timeline</strong>
[data] => Array
(
[url] => http://localhost/patient/face-timeline/
[type] => content
[cid] => 2291
[timeline] => 0
)
[children] => Array
(
[0] => Array
(
[key] => _2278
[title] => Post Op Visit
)
[1] => Array
(
[key] => _2277
[title] => Surgery
)
[2] => Array
(
[key] => _2276
[title] => Pre-Op
)
[3] => Array
(
[key] => _2275
[title] => Consultation
)
[4] => Array
(
[key] => _2274
[title] => Reseach
)
)
)
)
)
)
)
)
Da tale matrice voglio che questo array (sotto):
Array
(
[key] => _6
[title] => <strong>face timeline</strong>
[data] => Array
(
[url] => http://localhost/patient/face-timeline/
[type] => content
[cid] => 2291
[timeline] => 0
)
[children] => Array
(
[0] => Array
(
[key] => _2278
[title] => Post Op Visit
)
[1] => Array
(
[key] => _2277
[title] => Surgery
)
[2] => Array
(
[key] => _2276
[title] => Pre-Op
)
[3] => Array
(
[key] => _2275
[title] => Consultation
)
[4] => Array
(
[key] => _2274
[title] => Reseach
)
)
)
Ecco quello che ho provato
function recursion($array,$postid) {
foreach ($array as $key=>$value) {
if((isset($value['data']['cid'])) && ($value['data']['cid'] == $postid)){
$tmp = $value;
return $value;
}
if (is_array($value))
{
recursion($value,$postid);
}
}
}
Questa funzione non restituisce valori.
Qui $postid
è 2291
. Cioè che il mio e io sono in grado di stampare tale matrice, ma non può in grado di restituire il valore Ecco link
Dov'è il tuo codice? – artsylar
Con l'esempio di array, per favore aggiungi anche il codice qui o in fiddle –