我有这个数组:
Array
(
[0] => Array
(
[name] => Dick Jansen
[matchedMovie] => Array
(
[0] => Array
(
[nameMovie] => Saw
[genre] => Horror
[patheMovie] => Texas Chainsaw 3D
[patheMovieGenre] => Horror
[score] => 100.00
)
)
)
[1] => Array
(
[name] => Jim Scott
[matchedMovie] => Array
(
[0] => Array
(
[nameMovie] => Shooter
[genre] => Action, Thriller
[patheMovie] => The Shining
[patheMovieGenre] => Horror, Suspense/Thriller
[score] => 52.38
)
[1] => Array
(
[nameMovie] => Resident Evil Movie
[genre] => Action/Horror
[patheMovie] => Texas Chainsaw 3D
[patheMovieGenre] => Horror
[score] => 63.16
)
)
)
)
我想搜索 [patheMovie] 值(如“The Shining”)并获取带有 [name] 的父数组加上仅带有匹配的 [patheMovie] 的 [matchedMovie] 数组。
我试过这样的事情:
$search='Texas Chainsaw 3D';
$sorted=false;
foreach ($sorted as $n=>$c)
if (in_array($search,$c)) {
$cluster=$n;
break;
}
例如,如果我搜索“The Shining”,我希望数组返回如下:
Array
(
[0] => Array
(
[name] => Dick Jansen
[nameMovie] => Saw
[genre] => Horror
[patheMovie] => Texas Chainsaw 3D
[patheMovieGenre] => Horror
[score] => 100.00
)
)
and if you search for 'Texas Chainsaw 3D' like so:
Array
(
[0] => Array
(
[name] => Dick Jansen
[nameMovie] => Saw
[genre] => Horror
[patheMovie] => Texas Chainsaw 3D
[patheMovieGenre] => Horror
[score] => 100.00
)
[1] => Array
(
[name] => Jim Scott
[nameMovie] => Resident Evil Movie
[genre] => Action/Horror
[patheMovie] => Texas Chainsaw 3D
[patheMovieGenre] => Horror
[score] => 63.16
)
)