How to make array in PHP

If you want to know how to make array in PHP language so, you must know about what is an array. In PHP an array is an dynamic ordered map that can hold many values or elements in a single variable and the values or elements can be access by referring to an index number. Below is a simple example for you can understand.

<?php
$vegetables = ["Tomato", "Potato", "Carrot", "Cabbage"];
print_r($vegetables);
echo "<br>"; 
echo $vegetables[0]; 
echo "<br>"; 
echo $vegetables[1];
echo "<br>"; 
echo $vegetables[2]; 
echo "<br>"; 
echo $vegetables[3]; 
echo "<br>"; 
echo "My favorite vegetable is - $vegetables[0]";
?>

Leave a Comment