Mam dużą tablicę wielowymiarową. I muszę znaleźć z tego konkretną pod-tablicę.
Próbowałem użyć jednej funkcji rekursji, ale w rzeczywistości nie zwraca wartości. Czy ktoś może mi dać inne rozwiązanie.
Oto podgląd tablicy.Uzyskaj konkretną wartość z wielowymiarowej tablicy
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
)
)
)
)
)
)
)
)
Od tej tablicy chcę to array (poniżej):
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
)
)
)
Oto co próbowałem
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);
}
}
}
Ta funkcja nie zwraca wartości.
Tutaj $postid
jest 2291
. Że ja szukam i jestem w stanie wydrukować tej tablicy, ale nie może w stanie zwrócić wartość Tu jest link
Gdzie jest twój kod? – artsylar
W przykładzie z Array proszę również dodać kod tutaj lub w skrzypcach –