Search code examples
phpmysqlkey

How can i get the value from collection in php


I have data store in the below format

 [{"id":"927","store_id":"63","cover":"Banana.png","name":"Organic Banana / Kela / Keli"}]

I need to fetch the name and all the key value pairs. but don't know how to do it in Core PHP. If anyone helps it would be greate. Thanks :)


Solution

  • https://www.php.net/manual/en/function.json-decode.php

    $json = '[{"id":"927","store_id":"63","cover":"Banana.png","name":"Organic Banana / Kela / Keli"}]';
    $json_decoded = json_decode($json, true);
    foreach ($json_decoded as $product){
        echo($product['name']);
        // get others similarly
    }