I need to iterate over an array and do something where the actual value of the array is not needed. What is the most efficient way to do so? If I do need to use the array element value, does the answer change? I've given two possible solutions below.
<?php
$sql='INSERT INTO bla(x,y,z) ';
$myarray=array(4,3,6,9,6,3,6);
for ($i = 0; $i <= count($myarray); $i++) {
//Do something where $myarray[$x] is not needed such as make a sting
$sql.='(1,2,?),';
}
foreach($myarray as $arrayElement) {
//Do something where $arrayElement is not needed such as make a sting
$sql.='(1,2,?),';
}
?>