1

i have a json decoded array like $json = json_decode($curl_result); how to fetch this array using foreach loop and i want to reduce the array looping as much as possible. can you write the correct code that i can access these values.

the array is looking like below

  Array
  (
    [SITEResponse] => Array
    (
        [@version] => 1.0
        [SoftwareProducts] => Array
        (
            [@numFound] => 408
            [@numReturned] => 10
            [@start] => 0
            [SoftwareProduct] => Array
            (
              [0] => Array
                  (
                    [Summary] => Array
                    (
                         [$] => summery of software.
                    )
                    [Requirements] => Array
                    (
                    )

                    [ContentIds] => Array
                    (
                    )

                    [CleverBridgeUrl] => Array
                    (
                    )

                    [BuyNowUrl] => Array
                    (
                        [$] => http://www.abc.com
                        [@type] => dl_buy_pub
                    )

                    [BetaRelease] => Array
                    (
                        [$] => false
                    )

                    [LinkURL] => Array
                    (
                    [$] => http://www.abc.com
                    )
                )       
            )
        )
    )
)

now i want to get each value of this array but how??? please help thanks.

1
  • Create a function which gives you the output in a dynamic way. For example: foreach ($json as $key => $val) { if (is_array($val)) { CALL A FUNCTION THAT SCANS A ARRAY.. } } Else you can do it statically by specifying that array name: $output['SITEResponse'] will be Array $output['SITEResponse']['version'] will be 1.0 similarly you can do this other values.. Commented Nov 16, 2011 at 16:15

1 Answer 1

1
$version = $json['SITEResponse']['@version'];
$numFound = $json['SITEResponse']['SoftwareProducts']['@numFound'];
...
...

foreach( $json['SITEResponse']['SoftwareProducts']['SoftwareProduct'] as $key=>$product ){
$Summary= $product['Summary']['$'];
$BuyNowUrl = $product['BuyNowUrl']['$'];
...
...
...
}
Sign up to request clarification or add additional context in comments.

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.