Why can’t I use variable which contains a number to specify an array value:
$info(array)
$mySQLHeadings(array)
$infoString(empty String)
$mySQLHeadingString(empty string)
for ($i=0; $i<=count($info) ; $i++){
if($info[$i] != ""){
$mySQLHeadingString .= $mySQLHeadings[$i] . ",";
$infoString .= "'". $info[$i] ."',";
}
}
PHP says it’s an undefined offset $i in the arrays. How can I correct it or do something similar. Thank you so much.
If $info is numerically indexed, you can access elements with $i, but not further than max index !
count() gives you the array length, but max numeric index is (length – 1)
so :