I get the error Fatal error: Cannot use [] for reading on line
at return $array[];
inside the function.
I'm using PHP Version 7.0.1 on Windows 10.
I'm trying to get the output as follows:
<i>Error Line One...</i><br>
<i>Error Line Two...</i><br>
, in json_encode
{"s":"Error Line One...<\/i>Error Line Two...<\/i>","success":false}
I previously used a different approach, but switched to this yesterday.
How can I get this work?
$errorCount = 1;
$errors[] = '*Error Line One...';
$errors[] = '*Error Line Two...';
$errors['success'] = ($errorCount == 0 ? True : False);
$errors[] = ajax($errors);
function ajax($array) {
$array = preg_replace('#\*(.+?)(?![^*])#','<i>$1</i><br>',$array);
return $array[];
}
json_encode($errors);
Below is how it was done previously, then changed to the above to avoid the .=
parts. This approach works. See Fiddle.
$errorCount = 1;
$errors['s'] = '*Error Line One...';
$errors['s'] .= '*Error Line Two...';
$errors['s'] = ajax($errors);
function ajax($array) {
$array = preg_replace('#\*(.+?)(?![^*])#','<i>$1</i>',$array);
return $array['s'];
}
$errors['success'] = ($errorCount == 0 ? True : False);
echo json_encode($errors);