Question

Json Decode,

{"3C0DE946-3E0F-A924-F1C8-1FA723A23299":"apple","D6E3D33B-ED3E-7CE1-365F-321DA17540A0":"mango"}

I want to print the key and value seperatly from this array .

Was it helpful?

Solution

Make use of json_decode()

<?php
$str='{"3C0DE946-3E0F-A924-F1C8-1FA723A23299":"apple","D6E3D33B-ED3E-7CE1-365F-321DA17540A0":"mango"}';
$str=json_decode($str);

print_r($str);

OTHER TIPS

That's not a php array, that a small portion of JSON. To handle it in PHP you can do the followin:

<?php
    $json  = '{"3C0DE946-3E0F-A924-F1C8-1FA723A23299":"apple","D6E3D33B-ED3E-7CE1-365F-321DA17540A0":"mango"}';
    $array = json_decode($json, 1);

    foreach ($array as $key => $value) {
        echo "Key - $key\nValue - $value\n\n";
    }

Output:

Key - 3C0DE946-3E0F-A924-F1C8-1FA723A23299
Value - apple

Key - D6E3D33B-ED3E-7CE1-365F-321DA17540A0
Value - mango
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top