Php – Using loops to create arrays

arraysdata-structuresloopsphp

I am extremely new at php and I was wondering if someone could help me use either a for or while loop to create an array 10 elements in length

Best Solution

$array = array();
$array2 = array();

// for example
for ($i = 0; $i < 10; ++$i) {
    $array[] = 'new element';
}

// while example
while (count($array2) < 10 ) {
    $array2[] = 'new element';
}

print "For: ".count($array)."<br />";
print "While: ".count($array2)."<br />";