I have the following PHP array:
array(3) {
["NDQ"]=>
array(2) {
[0]=>
string(6) "Google"
[1]=>
string(5) "Yahoo"
}
["NYSE"]=>
array(2) {
[0]=>
string(5) "3M Co"
[1]=>
string(19) "Abbott Laboratories"
}
["FX"]=>
array(1) {
[0]=>
string(17) "Euro vs US Dollar"
}
}
I want to save this as a JSON document so I do the follwoing:
$instrument_names = json_encode($instrument_names, JSON_FORCE_OBJECT);
file_put_contents("../data/instrument_names.json", $instrument_names);
But the JSON file I get is as follows:
{
"NDQ":
{
"0":"Google",
"1":"Yahoo"
},
"NYSE":
{
"0":"3M Co",
"1":"Abbott Laboratories"
},
"FX":
{
"0":"Euro vs US Dollar"
}
}
where each name has been given a key as the index of the array (which was sequentially numbered).
How do I turn this into an array instead?
"NDQ":
{
["Google","Yahoo"]
}