<?php
$array = [
[
'name' => 'Dick Jansen',
'matchedMovie' => [
[
'nameMovie' => 'Saw',
'genre' => 'Horror',
'patheMovie' => 'Texas Chainsaw 3D',
'patheMovieGenre' => 'Horror',
'score' => '100.00',
]
]
],
[
'name' => 'Jim Scott',
'matchedMovie' => [
[
'nameMovie' => 'Shooter',
'genre' => 'Action, Thriller',
'patheMovie' => 'The Shining',
'patheMovieGenre' => 'Horror, Suspense/Thriller',
'score' => '52.38',
],
[
'nameMovie' => 'Resident Evil Movie',
'genre' => 'Action/Horror',
'patheMovie' => 'Texas Chainsaw 3D',
'patheMovieGenre' => 'Horror',
'score' => '63.16',
]
]
]
];
function findMovieMatches(array $movies, string $movieName): array
{
$result = [];
foreach ($movies as ['name' => $name, 'matchedMovie' => $matches]) {
foreach ($matches as $entry) {
if ($movieName === $entry['patheMovie']) {
$result[] = ['name' => $name] + $entry;
}
}
}
return $result;
}
var_export(findMovieMatches($array, 'Texas Chainsaw 3D'));
echo "\n---\n";
var_export(findMovieMatches($array, 'The Shining'));
- Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- 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',
),
)
---
array (
0 =>
array (
'name' => 'Jim Scott',
'nameMovie' => 'Shooter',
'genre' => 'Action, Thriller',
'patheMovie' => 'The Shining',
'patheMovieGenre' => 'Horror, Suspense/Thriller',
'score' => '52.38',
),
)
preferences:
124.95 ms | 403 KiB | 89 Q