0
<?php
        $fortressMapping = [
            1 => <img src="<?php echo $image_url;?>">,'JG Fortress',
            3 => <img src="<?php echo $image_url;?>">,'HT Fortress',
            4 => <img src="<?php echo $image_url;?>">,'Ban Fortress',
            6 => <img src="<?php echo $image_url;?>">,'Ban Fortress',
    ];

How can I insert image in this code

LF00
  • 24,667
  • 25
  • 136
  • 263
Ahmed Mamdouh
  • 273
  • 1
  • 5
  • 17

3 Answers3

0

You should use it like this to add element to your array, live demo

<?php
    $fortressMapping = [
       1 => "<img src=\"<?php echo $image_url;?>\">,'JG Fortress'",
            .....
    ];
LF00
  • 24,667
  • 25
  • 136
  • 263
0

Remove echo inside $fortressMapping

<?php
$image_url = "http://example.com/image.png";
        $fortressMapping = [
            1 => '<img src="$image_url">','JG Fortress',
            3 => '<img src="$image_url">','HT Fortress',
            4 => '<img src="$image_url">','Ban Fortress',
            6 => '<img src="$image_url">','Ban Fortress',
    ];

    print_r($fortressMapping);
Adharsh M
  • 2,713
  • 2
  • 18
  • 31
0

You can't echo inside the var assignment:

$fortressMapping = [
            1 => "<img src='{$image_url}'>",'JG Fortress',
            3 => "<img src='{$image_url}'>",'HT Fortress',
            4 => "<img src='{$image_url}'>",'Ban Fortress',
            6 => "<img src='{$image_url}'>",'Ban Fortress',
    ];
capcj
  • 1,535
  • 1
  • 14
  • 21