I'm very new to PHP and just code in general, so my apologizes if my code looks like a mess.
I've created a multidimensional array and when certain checkboxes are selected and submitted through the form, I want only the selected arrays items show. Such as, John Smith's information and image only if just he is selected.
Here is my multidimensional array:
<?php
$characters = array (
'john' =>
array (
'first_name' => 'John',
'last_name' => 'Smith',
'age' => '40',
'image_url' => 'images/john.png',
),
'jane' =>
array (
'first_name' => 'Jane',
'last_name' => 'Doe',
'age' => '30',
'image_url' => 'images/jane.png',
),
'sara' =>
array (
'first_name' => 'Sara',
'last_name' => 'Johnson',
'age' => '10',
'image_url' => 'images/sara.png',
)
)
?>
And here is my html form:
<h3 class="form__heading"> Select characters to show </h3>
<form method="post">
<ul class="form__items">
<!--John-->
<li class="form__item">
<label for="john">John Smith </label>
<input id="john" type="checkbox" name="john">
</li>
<!--Jane-->
<li class="form__item">
<label for="jane">Jane Doe </label>
<input id="jane" type="checkbox" name="jane">
</li>
<!--Sara-->
<li class="form__item">
<label for="sara">Sara Johnson </label>
<input id="sara" type="checkbox" name="sara">
</li>
</ul>
<!--Button-->
<input class="form__button" type="submit" value="Show Characters">
</form>
I have tried foreach and for loops, but I think I'm just doing it wrong. Any help is greatly appreciated!