css — назначить стиль, если массив php содержит значение

Привет, я использую API-интерфейс tmdb и загружаю список фильмов об актерах. код работает так, как я хочу, кроме того, что я пытаюсь стилизовать миниатюру фильма иначе, чем остальные, если фильм ужасов.

$tmdb = $_GET['tmdb'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.themoviedb.org/3/person/".$tmdb."?api_key=#######");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
$person = curl_exec($ch);
curl_close($ch);
$actor= json_decode($person, true); // Decode the results into an array
$name = $actor['name'];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.themoviedb.org/3/discover/movie?&with_cast=".$tmdb."&vote_count.gte=5&sort_by=release_date.desc&api_key=#######");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
$personCredits = curl_exec($ch);
curl_close($ch);
$credits= json_decode($personCredits, true); // Decode the results into an array

$counter4 = 0;
$counter5 = 0;
echo "<pre>";
print_r($credits);
echo "</pre>";

$page=1;
echo "<div style='width:800px;overflow:hidden;position:absolute;ktop:1100px;left:75'>";

while ( $page <= $credits['total_pages'] ) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.themoviedb.org/3/discover/movie?&with_cast=".$tmdb."&vote_count.gte=5&sort_by=release_date.desc&page=".$page."&api_key=#######");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
$personCredits = curl_exec($ch);
curl_close($ch);
$credits= json_decode($personCredits, true); // Decode the results into an array

$resultsCount4=(count($credits['results']))-1;
while ( $counter4 <= $resultsCount4 ) {

// THIS IS WHERE I NEED HELP PLEASE>>>>>
if($credits['results'][$counter4]['genre_ids'] == 27) {
$style="horror";
} else { $style="round"; }
////////////////////////////////////////////////////

echo "<div style='width:200;height:260;float:left;text-overflow:ellipsis    white-space: nowrap;
width: 14em;
overflow: hidden;
'><center><div class='".$style."'><a href=\"/?id=moviepage.php&ttno=".$credits['results'][$counter4]['id']."\"><img width=\"154\" height=\"231\"onerror=\"this.src='nocover.png'\" src='http://image.tmdb.org/t/p/w154/".$credits['results'][$counter4]['poster_path']."'></div><br>".$credits['results'][$counter4]['title']."<br>".$credits['results'][$counter4]['release_date']."</center></a></div>";
$counter4++;
}
$page++;
$counter4=0;
}

массив Json выглядит как

    Array
(
[page] => 1
[results] => Array
(
[0] => Array
(
[poster_path] => /ceVMgY3TzLrfEpaMfaOnPDYnfqA.jpg
[adult] =>
[overview] => John Wick is forced out of retirement by a former associate looking to seize control of a shadowy international assassins’ guild Bound by a blood oath to aid him, Wick travels to Rome and does battle against some of the world’s most dangerous killers.

[release_date] => 2017-02-10
[genre_ids] => Array
(
[0] => 28
)

[id] => 324552
[original_title] => John Wick: Chapter Two
[original_language] => en
[title] => John Wick: Chapter Two
[backdrop_path] => /6TPIMjoyRKCKhCGeGigP99qQTWw.jpg
[popularity] => 1.714191
[vote_count] => 7
 =>
[vote_average] => 9.57
)

[1] => Array
(
[poster_path] => /l9Eu1e3qNvFSvi66WtHFBoHIgeT.jpg
[adult] =>
[overview] => A defense attorney works to get his teenage client acquitted of murdering his wealthy father.
[release_date] => 2016-06-10
[genre_ids] => Array
(
[0] => 18
[1] => 53
)

[id] => 331583
[original_title] => The Whole Truth
[original_language] => en
[title] => The Whole Truth
[backdrop_path] => /1pwF12CCtUSmCifDGhZHohp5qYu.jpg
[popularity] => 1.875005
[vote_count] => 6
 =>
[vote_average] => 6.67
)

заранее спасибо

0

Решение

genre_ids является массивом (обратите внимание, что имя множественного числа, а «Вся правда» в двух жанрах), а не число, поэтому

if($credits['results'][$counter4]['genre_ids'] == 27)

не сработает использование in_array()

if (in_array(27, $credits['results'][$counter4]['genre_ids'])
0

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]