I want to write both a string and an array to a file using file_put_contents in php. To write the array, I'm able to do:
file_put_contents('filename.js', json_encode(array(
'status' => TRUE,
'data' => $data
), JSON_NUMERIC_CHECK));
The resulting file then appears as:
{status:true,data:dataArray}
I would simply like to put a string before that array in the file so that it reads:
var myData = {status:true,data:dataArray}
I've tried the following unsuccessfully:
file_put_contents('all_model_data.js', json_encode("var myData =", array(
'status' => TRUE,
'data' => $data
), JSON_NUMERIC_CHECK));
And
file_put_contents('all_model_data.js', ("var myData =", json_encode(array(
'status' => TRUE,
'data' => $data
), JSON_NUMERIC_CHECK)));
Any tips? Thanks,