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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -