Pages

Tuesday, 23 February 2016

Dynamic Array in PHP

     The array is a collection of similar data types which occupies continuous location in memory. There are two types of array static and dynamic. In dynamic array size can be decreased and increase as requirement which best uses of memory utilization on the other hand static array is fixed in nature you cannot increase and decrease array capacity when require so it’s not popular in PHP. We deal with mostly dynamic array in PHP.

Dynamic Array example code :

<?php

$ar=array("Red","Green","Blue");
for($i=0;$i<count($ar);$i++)
{
echo  "<br>" . ($i+1) . "'st element value " . $ar[$i];
}
?>

Example 2:

$ar[]="";
for ($i = 0; $i <$10; $i++)
{
array_push($ar,$i);
}

for($i=0;$i<count($ar);$i++)
echo "<h2>" . $ar[$i] . "</h2>";

No comments:

Post a Comment