Jump to content

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


jonnyenglish89

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.