I want to make a selection display like the following in html:
<div name="option_a">
<p>result for option_a</p>
<img src="option_a_image"></img>
</div>
<div name="option_b">
<p>result for option_b</p>
<img src="option_b_image"></img>
</div>
<div name="option_c">
<p>result for option_c</p>
<img src="option_c_image"></img>
</div>
<div name="option_d">
<p>result for option_d</p>
<img src="option_d_image"></img>
</div>
using this array :
Array
(
[0] => stdClass Object
(
[option_a] => its option a
[option_a_image] => its an image for option a
[option_b] => its option b
[option_b_image] => its an image for option b
[option_c] => its option c
[option_c_image] => its an image for option c
[option_d] => its option d
[option_d_image] => its an image for option d
)
[1] => stdClass Object
(
[option_a] => its option a
[option_a_image] => its an image for option a
[option_b] => its option b
[option_b_image] => its an image for option b
[option_c] => its option c
[option_c_image] => its an image for option c
[option_d] => its option d
[option_d_image] => its an image for option d
)
[2] => stdClass Object
(
[option_a] => its option a
[option_a_image] => its an image for option a
[option_b] => its option b
[option_b_image] => its an image for option b
[option_c] => its option c
[option_c_image] => its an image for option c
[option_d] => its option d
[option_d_image] => its an image for option d
)
)
but I wanted to make it more concise using loops. I have tried the following:
<?php foreach($array[0] as $type=>$value ){
if(strpos($type,'option_') !== false){ ?>
<div class="card mb-3" style="width: 98%; margin: auto">
<div class="card-body">
<label ><input type='radio' name='r1' tabindex='5'> <span><?php echo $value ?></span></label> <br>
</div>
</div>
<?php } } ?>
but loops like this can't produce the view I want to create. So how do I get the loop to form the result I want to produce?
Thank you