PHP Array with images and text

I am trying to display an Image in a PHP Array. So basicly what I've got:
View:
<?php
include "controllers/Autos.php";
?>
<!DOCTYPE html>
<html>
<head>
<title>Autos</title>
</head>
<body>
<?php
foreach($mercedesRood as $value){
echo $value . "<br>";
}
?>
</body>
</html>
Controller:
<?php
include "models/autos.php";
$mercedesRood = array('image' => "$mercedesRoodImage","$mercedesRoodKleur","$mercedesRoodMerk");
class Autos extends Controller{
}
?>
Model:
<?php
$mercedesRoodImage = ("./libs/MercedesRood.jpg");
$mercedesRoodMerk = "Mercedes";
$mercedesRoodKleur = "Rood";
$bmwZwartImage = ("./libs/BmwZwart.jpg");
$bmwZwartMerk = ("BMW");
$bmwZwartKleur = ("Zwart");
?>
Right now it's a string but I need to convert the string to an URL. (Yes, my .htacces is set correctly because I tested it before by just using the variable and not the array.)
Answer
Solution:
Update the array in your controller with indexes. Like this:
<?php
include "models/autos.php";
$mercedesRood = array(
'image' => $mercedesRoodImage,
'color' => $mercedesRoodKleur,
'brand' => $mercedesRoodMerk
);
Next, you can show the images within the view, using that index:
<?php
include "controllers/Autos.php";
?>
<!DOCTYPE html>
<html>
<head>
<title>Autos</title>
</head>
<body>
<?php
echo '<img src="'.$mercedesRood['image'].'">';
?>
</body>
</html>
Please take a look at https://www.php.net/manual/en/language.types.array.php for more information about array's.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: trying to access array offset on value of type bool
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.