How can an array be constructed in PHP to be passed as JSON to AJAX?
To construct an array in PHP that can be passed as JSON to AJAX, you can create an associative array with key-value pairs representing the data you want to send. Then, use the json_encode() function to convert the array into a JSON string that can be sent to the client-side. Finally, echo or return the JSON string in your PHP script to be received by the AJAX request.
$data = array(
'name' => 'John Doe',
'age' => 30,
'email' => 'john.doe@example.com'
);
echo json_encode($data);