Jump to content

How do I get specific values from a json encoded string?


jonnyenglish89
 Share

Go to solution Solved by requinix,

Recommended Posts

Hey guys,

 

I needed to covert the $main array in to a string so I used json_encode to do it but now I’m unsure how to get just the key values for $main[0] and $main[1] – can anyone help?


main array:

Array
(
    [0] => Array
        (
            [25256] => 1
        )

    [1] => Array
        (
            [50005] => 1
        )

    [2] => Array
        (
            [301] => 1
            [2318] => 1
            [13403] => 1
            [49489] => 1
        )

)

current code and output:

$com_id = json_encode($main[0]); = {"25256":1}
	
$dom_id = json_encode($main[1]); = {"50005":1}
	
$car_id = json_encode($main[2]); = {"301":1,"2318":1,"13403":1,"49489":1}

Desired output:

$com_id = {"25256"}
	
$dom_id = {"50005"}
	
$car_id = {"301":1,"2318":1,"13403":1,"49489":1}
Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.