php - Push array into JSON but got unwanted result -


I used to suck on formatting, maybe I had a bad foundation. I have a Jason

  'first_name' = & gt; 'Steve', 'msg' = & gt; 'Something Here', 'Profile_ID' = & gt; 1  

And I want to push a new item into it, I wrote

  $ i = array ('first_name' = & gt; 'Steve ',' Msg '= & gt; some here', 'profile_id' => 1); $ LoginId = array ($ _ GET ['login_id']); Array_push ($ i, $ loginID); Echo json_encode ($ i);  

The result is strange to me:

< / Div>

  $ i = array ('first_name' = & gt; 'steve', 'msg' = & Gt; Here some ',' Profile_ID '=> 1); $ LoginId = $ _GET ['login_id']; $ I ['login_id'] = $ LoginID; Echo json_encode ($ i);  

The reason array_push is not working because you are treating $ i as an array of objects (collections), whereas this is just an important value list (map) ) is.

If the array is like K1 => V1, K2 => V2, then use $ arr [K3] = V3 to add another pair.

If the array is like [(k1, V1), (k2, v2)], then array_push ($ arr, (k3, v3));


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -