1

I need a PHP way to show only store_name in PHP

I have tried the following with no success

    <?php
require_once("admin/system/core.php");
$fetch = new server();
$fetch->connect();
$store = $fetch->getstore("movies");

print $store;
?>

the JSON looks like this [{"_id":{"$id":"4f67da1538fc5d7347000000"},"store_name":"movies","categories":{"name":"hoyts","products":{"name":"GoldClass","Price":"12.00","CashBack":"2.00"}}}]

1
  • Have you tried, you know, parsing it? Commented Mar 20, 2012 at 6:08

2 Answers 2

2

I assume the returned value is json string. So you have to decode it from string to an object with json_decode function

$store = $fetch->getstore("movies");
$data  = json_decode($store);

foreach($data as $d) {
    echo $d->store_name;
}
Sign up to request clarification or add additional context in comments.

Comments

1

assuming your array will be

$array = array('id'=>'4f67da1538fc5d7347000000',
        'store_name'=>'movies');
echo $json = json_encode($array);

it echo's

{"id":"4f67da1538fc5d7347000000","store_name":"movies"}

then you can use

$data = json_decode($json);
echo $data->store_name;

which echo's movies

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.