I recently posted this question on Stack - Search array for specific string - and got the perfect answer for my question, which I marked as correct. However I now have a related issue, which I'm finding tricky to solve, but it seems like it should be quite easy!
I have searched an array for the string 'GB' and 'US' using the following, which was provided to me on the previous post:
/* Get Movie release dates */
$releases = $tmdb->getMovieReleases($tmdb_id);
echo "<pre>";
print_r($releases);
echo "</pre>";
$uk_release = -1;
foreach($releases['countries'] as $k=>$v) {
if(array_search('GB', $v)) {
$uk_release = $k;
break;
} else {
$uk_release = null;
}
}
$us_release = -1;
foreach($releases['countries'] as $k=>$v) {
if(array_search('US', $v)) {
$us_release = $k;
break;
} else {
$us_release = null;
}
}
$uk_rating = $releases['countries'][$uk_release]['certification'];
$us_rating = $releases['countries'][$us_release]['certification'];
which is then parsed into the page using a simple <?php echo $uk_rating; ?>
/<?php echo $us_rating; ?>
.
I've found, however that some arrays don't actually contain the data the query is searching for, such as the following, which doesn't have a UK rating or release date:
Array
(
[id] => 13655
[countries] => Array
(
[0] => Array
(
[iso_3166_1] => US
[certification] => G
[release_date] => 2008-06-20
)
[1] => Array
(
[iso_3166_1] => CA
[certification] =>
[release_date] => 2008-06-20
)
[2] => Array
(
[iso_3166_1] => JP
[certification] =>
[release_date] => 2008-08-01
)
)
)
I've attempted to construct various IF statements to check if one of the two queries is null, empty, == "" etc etc. but nothing seems to work. Currently, I'm attempting the following, basically using the logic IF neither results are equal to nothing, show both, or if one of the two is empty, only show the one which isn't empty (apologies for the formatting):
if ($uk_date !== "" && $us_date !== "") {?>
<section class="span3">
<p class="overview-title">RELEASE DATE</p>
<p class="section_body">
<?php echo $uk_date; ?> (UK)<br>
<?php echo $us_date; ?> (US)
</p>
</section><?php
} else if ($uk_date = "") {?>
<section class="span3">
<p class="overview-title">RELEASE DATE</p>
<p class="section_body">
<?php echo $us_date; ?> (US)
</p>
</section><?php
} else if ($uk_date == "") {?>
<section class="span3">
<p class="overview-title">RELEASE DATE</p>
<p class="section_body">
<?php echo $uk_date; ?> (UK)
</p>
</section><?php
}