My question is the opposite of this Using two values for one switch case statement
I'd like to use multiple values in the switch part of the statement, not the case part which I already know how to do.
<?php
$three = json_decode( $ex[ 'three-images' ] );
$i = 0;
$imgs = $trans = $class = $parallaxDir = [];
foreach ( $three as $img ) {
$imgs[ $i ] = $img->Image;
$parallax[ $i ] = $img->Transition;
$class[ $i ] = $img->Class;
//for ($ii = 0; $ii < 3; $ii++) {
switch ( $class[ $i ] ) {
case 'middle':
case 'onright':
$parallaxDir[ $i ] = '0';
break;
case 'top':
case 'onleft':
$parallaxDir[ $i ] = '1';
break;
default:
$parallaxDir[ $i ] = '9';
break;
};
//}
$i++;
}
?>
<div class="side image <?php echo $class[1]; ?>" <?php if(!empty($parallax[1])) { echo 'data-para="' . $parallax[1] . '"'; } ?> <?php if(!empty($parallaxMob)) { echo 'data-para-mobile="' . $parallaxMob . '"'; } ?> <?php if(!empty($parallaxDir[1])) { echo 'data-para-dir="' . $parallaxDir[1] . '"'; } ?>>
<img class="parallax" src="<?php echo $imgs[1]; ?>" alt="<?php echo explode('[',trim($item->title)[0]); ?> image"/>
</div>
This is the full code, seems it was working fine as I had it but for some reason when trying to implement it later down the line the array values were returning as empty even though they weren't.
So once I took the [1]
off the parallaxDir if(!empty)
check it started working