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
  • 27,015
  • 29
  • 156
  • 295
Ahmed Mamdouh
  • 285
  • 2
  • 5
  • 18

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
  • 27,015
  • 29
  • 156
  • 295
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,773
  • 2
  • 20
  • 33
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
  • 16
  • 23