php - Assign Key to Existing Array -
Assume that I have an array like this example:
[{type "type And I want to specify this whole array by name as "dish" for a particular key: "food", "alias": "food"}]
How can I archive it?
The expected product should be something like this:
"dish": [{"type": "food", "nickname": "food"}] I know how to create new key values pairs but have never thought of assigning a key until now.
$ json = '[{"type": "food", "alias": " food "}]'; $ Data = json_decode ($ json, true); $ Data = array ('dish' = & gt; $ data); Echo json_encode ($ data);
Comments
Post a Comment