0
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);

print_r($jsonobj); //this shows me the op as:


Array ( 
[0] => 
    stdClass Object ( 
        [businessId] => 6 
        [subscriptionId] => 6 
        [name] => Eazy Borehole Drillers Limited 
        [city] => Blantyre 
        [pin] => 3332 
        [region] => Southern Region 
        [area] => City Centre 
        [address] => P.O. Box 3332 Blantyre 
        [email] => [email protected] 
        [website] => eazyboreholedrillers.com 
        [district] => Blantyre 
        [phonenumber] => 265999434445 
        [category] => 14 
) 
[1] => 
    stdClass Object ( 
        [businessId] => 7 
        [subscriptionId] => 7 
        [name] => Eazy Travel Limited 
        [city] => Blantyre 
        [pin] => 3332 
        [region] => Southern Region 
        [area] => City Centre 
        [address] => P.O. BOX 3332 Blantyre 
        [email] => [email protected] 
        [website] => eazytravell.com 
        [district] => Blantyre 
        [phonenumber] => 265999434445 
        [category] => 15 
) 
[2] =>
    stdClass Object ( 
        [businessId] => 20 
        [subscriptionId] => 20 
        [name] => Malswitch 
        [city] => Blantyre 
        [pin] => 384 
        [region] => Southern Region
        [area] => City Centre 
        [address] => PO Box 384 
        [email] => [email protected] 
        [website] => www.malswitch.com 
        [district] => Blantyre 
        [phonenumber] => 01 820 414 
        [category] => 69 
) 
[3] =>
    stdClass Object ( 
        [businessId] => 21 
        [subscriptionId] => 21 
        [name] => Malawi Savings Bank 
        [city] => Blantyre 
        [pin] => 521 
        [region] => Southern Region 
        [area] => Cicty Centre 
        [address] => PO Box 521 PO Box 521 
        [email] => [email protected] 
        [website] => www.msb.mw 
        [district] => Blantyre 
        [phonenumber] => 01 831 016 / 01 
        [category] => 69 
)

Now my question is how to take the inside values like [businessId],[subscriptionId] out of this so that i can use them in my html page.

4
  • 4
    a simple foreach should suffice: foreach($jsonobj as $key => $value) { echo $value->businessId; } etc.. something like that Commented Jun 12, 2014 at 10:14
  • you can try get_object_vars() php.net//manual/en/function.get-object-vars.php Commented Jun 12, 2014 at 10:20
  • @kevinabelita Thanks a lot... how easy it was... i was doing as echo $value[businessId].... :-)) Commented Jun 12, 2014 at 10:30
  • @SohamsMore since $jsonobj contains objects inside, each copy of $value inside the foreach is an object. to access its values you need to use the -> (arrow notation) to get them. your welcome. Commented Jun 12, 2014 at 10:34

2 Answers 2

1

you use this 'array->key'. example array->businessId;

$data = Array ( 
[0] => 
    stdClass Object ( 
        [businessId] => 6 
        [subscriptionId] => 6 
        [name] => Eazy Borehole Drillers Limited 
        [city] => Blantyre 
        [pin] => 3332 
        [region] => Southern Region 
        [area] => City Centre 
        [address] => P.O. Box 3332 Blantyre 
        [email] => [email protected] 
        [website] => eazyboreholedrillers.com 
        [district] => Blantyre 
        [phonenumber] => 265999434445 
        [category] => 14 
)
)

$data[0]->businessId;
$data[0]->subscriptionId;
Sign up to request clarification or add additional context in comments.

Comments

1

Your JSON object contains objects itself, which you can access with ->. Try this:

$jsonobj = ...; // Fetch your JSON object

foreach($jsonobj as $item) {
    echo $item->businessId;     // 6
    echo $item->subscriptionId; // 6
    echo $item->city;           // Blantyre
    echo $item->area;           // City Centre
}

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.