1
var_dump($products); 

Output: array(7) { [0]=> array(5) { ["Product"]=> array(40) { ["id"]=> string(3) "726" ["wbb"]=> string(1) "1" ["abb"]=> string(1) "0" }

But when I do var_dump($products['Product']['wbb']); it gives me NULL

How I will use the value of ["wbb"]

if(!empty($product)) :

If i dump $product, it gives me different products with details of each product.
Simple output of one product when I dump $product

array(7) { [0]=> array(5) { ["Product"]=> array(40) { ["id"]=> string(3) "726" ["wbb"]=> string(1) "1" ["abb"]=> string(1) "0" }

{ [1]=> array(5) { ["Product"]=> array(40) { ["id"]=> string(3) "727" ["wbb"]=> string(1) "0" ["abb"]=> string(1) "1" }

Similarly I have 10 more products with some of them are wbb = 1 and some of them are abb =1. I want to add tooltip according to the flag raised. But when I do like this $i++;

if(!empty($product[$i]['Product']['wbb'])){ echo code here.....}

becuase it iterates, so it will not give me according to exact product. How should I have to do it?

2
  • 1
    $products[0]['Product']['wbb'] Commented Mar 12, 2013 at 15:56
  • 1
    And where does the $product variable come from? Do you foreach over your $products? Please share all relevant code, otherwise we can't help you! Commented Mar 12, 2013 at 16:41

3 Answers 3

2

It looks like you should be using var_dump($products[0]['Product']['wbb']);

Sign up to request clarification or add additional context in comments.

Comments

2

If you look closely you will notice that the $products array is a multidimensional array, holding a numeric key for each data row (starting at 0). Any additional rows will get 1, 2 and so on. In order to get the mentioned wbb value of the first (and apparently only) row, use

var_dump($products[0]['Product']['wbb']);

Instead.

1 Comment

@AbrarKiyani In that case you have not shown us all your code. If I recreate the array as you pasted it and use the variable above, this code example outputs WBB is 1, as would be expected: gist.github.com/oldskool/5144154
2

$products is an array of multiple products. You should use:

var_dump($products[0]['Product']['wbb']);

1 Comment

And what would you call $products if the [0] key wasn't there? It's still an array regardless, this one is just multidimensional and numerically indexed per result row.

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.