// M7C1-LV
Indexed Arrays //24:10-indexed array
You can create an indexed array using the array() function or the short array syntax [].
How to create
$fruits1=array("apple","banana","cherry"); $fruits2=["apple","banana","cherry"];
- Simple echo will not show the array result without []
- print_r is use to get array result
print_r($fruits1); print_r($fruits2);
// Accessing Values of Indexed Array
echo $fruits1[2]; print_r($fruits2[1]);
How to loop over Indexed Arrays // 28:30
// For Loop through an Indexed Array
for ($i=0; $i<count($fruits1); $i++){ echo $fruits1[$i]."\n"; }
// foreach Loop through an Indexed Array
$app=['Android','IOS','Windows','Linux']; foreach($app as $item){ echo $item."\n"; }