I've seen multiple threads converting python dictionaries to json but nothing showing how to save a python dictionary or a json array to a PHP array. I have inherited a PHP array file that needs to be modified. I was able to do this thru the help of another thread or two. I know am able to open the existing php array file, make needed changes and store to a python dictionary. I have saved it to a json array file but need to get it to the original format as shown below in order for existing scripts to have access to the data.
<?php
error_reporting(0);
$items=array (
0 =>
array (
'name' => 'Ted',
'size' => 'Large',
'sleeve' => 'Short',
'color' => 'Red',
),
);
$unObiect->items = $items;
$json = json_encode($unObiect);
echo($json);
?>
Currently using :
with open('data.json', 'w') as outfile:
json.dump(r, outfile, sort_keys=True, indent=4, ensure_ascii=False)
Where the r is the python dictionary. The result of this array looks like:
{
"items": [
{
"name": 'Ted',
"size": 'Large',
"sleeve": 'Short,
"color": 'Red',
},
Is there a way to retain the php array style with either the dictionary or the json array?
The reference duplicate is not the same. I do not wish to parse a json with PHP, I want to use Python to save to PHP array.
EDIT: Ignore all references to JSON in this thread. I only wish to save a Python dictionary to a PHP array in the format shown.