Inserting Array Elements into HTML Code
You can also insert array elements. Let's see how it's done. Suppose we have the following array:
<?php
$arr = [1, 2, 3, 4, 5];
?>
Let's insert each of its elements into a separate paragraph:
<p><?= $arr[0] ?></p>
<p><?= $arr[1] ?></p>
<p><?= $arr[2] ?></p>
<p><?= $arr[3] ?></p>
<p><?= $arr[4] ?></p>
Given an array:
<?php
$arr = ['a' => 1, 'b' => 2, 'c' => 3];
?>
Also given three paragraphs:
<p></p>
<p></p>
<p></p>
Perform the insertion of the array elements into the corresponding paragraphs.