Can someone see what I’m doing wrong with this php array? I”m trying to create a dynamic array but somehow it not working and get an Server internal error when attempting to access it from a browser
$index = 0;
$columnIndex = 0
while($row = mysqli_fetch_array($result, MYSQL_NUM))
{
$test = array();
$test[$arrayIndex] = $row[$columnIndex];
$coumnIndex = 1;
if(is_string($row[$number]))
{
preg_match("/(?:\d+\.)?(?:\s*)?$stop?(?:\s*)?(.*):(.*)",{$row[$columnIndex]},$match1);
$test[$index] = '<p> <strong> . $match1[1] . </strong> . $match1[2] . </p>';
}
++$arrayIndex;
++$columnIndex;
}
$jsonData = json_encode($test);
echo $jsonData;
You’re getting the error most likely because you’re doing
$test[$arrayIndex] = $row[$columnIndex];when I don’t see$arrayIndexdefined (thus it’s null). You can’t set a null array index.If you want a simple dynamic array in PHP, you could do something like this instead:
And you’ll wind up with an array
$testthat contains whatever you put in/* something */on each line. Look at the section entitled “Creating/modifying with square bracket syntax” on the PHP Arrays page.