1

hi im new to api calling and i seem to have a problem with getting an item called price from my array. The following is the array that I am supposed to extract price from.

Array
(
    [prodId] => ROC-PRD-2
    [prodName] => iphone 6
    [projectId] => 8
    [categoryIds] => Array
        (
            [0] => ROC-CAT-1
        )

    [prodParentSku] => iph6a1
    [prodMetaTitle] => iphone 6
    [visible] => 1
    [prodStatus] => 1
    [modifiedDate] => 1443472415
    [createDate] => 1443472193
    [productImages] => Array
        (
            [0] => Array
                (
                    [id] => 89
                    [imageName] => iphone-ipad hi res.png
                    [imagePath] => http://tos-staging-web-server-s3.s3.amazonaws.com/8/products/ROC-PRD-2/iphone_ipad_hi_res.png
                    [visible] => 1
                    [featured] => 
                    [modifiedDate] => 1443472390
                    [createDate] => 1443472390
                )

            [1] => Array
                (
                    [id] => 90
                    [imageName] => ipad 2.jpg
                    [imagePath] => http://tos-staging-web-server-s3.s3.amazonaws.com/8/products/ROC-PRD-2/ipad_2.jpg
                    [visible] => 1
                    [featured] => 
                    [modifiedDate] => 1443472397
                    [createDate] => 1443472397
                )

        )

    [pricing] => Array
        (
            [price] => 1000
            [memberGroupPrices] => Array
                (
                )

        )

)

I am able to get the product images information such as id, imagepath, using the following for loop

foreach ( $product['productImages'] as $key => $data){
    foreach ($data as $key => $eachImage){
 }
}

However for price my code is as follow:

foreach ( $product['pricing'] as $key => $price){

}

If i echo the $price i would get "1000Array" If i echo $price['price'], nothing comes out.

1
  • 4
    If there's a single field having price then you can simply use echo $product['pricing']['price']; instead of looping Commented Nov 18, 2015 at 8:58

3 Answers 3

1

You Dont need to look for $pricing as its its single;

$price = $product["pricing"]["price"];
$memberGroupPrices = $product["pricing"]["memberGroupPrices"];
Sign up to request clarification or add additional context in comments.

Comments

1

Just print the price with out looping

 $price = $array["pricing"]["price"];

Comments

1

Please check with this

foreach ( $product['pricing'] as $key => $price){ 
        if($key=='price')
          $price_val=$price;
}

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.