I am trying to display an image, where the path is defined in an array not from a database.
First index.php calls app/app.php, which then includes the $animals array from animals.php.
The problem is how do I access $animals in index.php and get the value of the pics key?
index.php
<?php require_once __DIR__ . '/app/app.php';
//var_dump($animals);?>
<?php foreach ($animals as $animal): ?> <br>
<a href="#"><?php echo $animal['name'] ?></a>
<?php echo $animal['size'] ?>
<img src="<?php echo $animal['pics'] ?>" alt="Pic 1">
<?php //echo "<img src='" . $pics . "' alt=''>"; ?>
<?php endforeach; ?>
app/app.php:
<?php
ini_set('display_errors', '1');
error_reporting('E_ALL');
$animals = require_once __DIR__ . '/Db/animals.php';
animals.php:
<?php
return [
[
'name' => 'cow',
'size' => 20,
'pics' => ['/photos/cow1.jpg'],
//'pics' => 'photos/cow1.jpg',
//'pics' => '<img class="wrap" src="photos/cow1.jpg">',
//'pics' => './photos/cow1.jpg';
'detailes' => [
'colour' => 'brown',
'origin' => 'N Italy',
],
],
];
It's frustrating that I can't solve it. Maybe someone could help.
$animal['pics'][0]is the first onevar_dumpis your friend. Maybe with xdebug for pretty output. Good to get in habit of deciphering those dumps.