1

I have a long object stored in an array. I am trying to display an specifics values of this array.

The problem is the following:


foreach($reportVal["OrderEventDetail"] AS $OrderEventDetailK => $OrderEventDetailV){
  print_r($reportVal["OrderEventDetail"]);
}

Output:

Array ( 
       [eventId] => 18345
       [orderId] => 781 
      )


Array ( 
      [eventId] => 18345 
      [orderId] => 781 
       ) 

Everything is ok at this point, but:


foreach($reportVal["OrderEventDetail"] AS $OrderEventDetailK => $OrderEventDetailV){
  $OrderEventDetailV["orderId"];
}

Output:

1 7

Why its happening? If im printing ["orderId"], the value would be 781 781.

Expected result:

<span class="label label-success" style="background-color: #5cb85c;">Orden <?= $OrderEventDetailV["orderId"] ?></span>

With value:

<span class="label label-success" style="background-color: #5cb85c;">Orden 781</span>
3
  • 1
    What are you expecting from just single $OrderEventDetailV["orderId"]; in loop body? Commented Feb 6, 2014 at 13:16
  • I just edited your code to add the necessary print_r that many comments and answers have indicated must be there. Can you please confirm whether this solves the problem? Commented Feb 6, 2014 at 13:28
  • @DanNissenbaum, editors should not modify the OP's code (only minor formatting is allowed). Use comments or your own answer for that. Commented Jun 25, 2014 at 11:04

4 Answers 4

2

You need to echo $reportVal["OrderEventDetail"]["orderId"];

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

Comments

2

Don't you want to be doing a

print_r($OrderEventDetailV["orderId"]);

in your loop?

1 Comment

No. the array is $reportVal["OrderEventDetail"], i want the value in $OrderEventDetailV["orderId"] key.
1

Try This Code

echo "<pre>";
foreach($reportVal["OrderEventDetail"] AS $OrderEventDetailK => $OrderEventDetailV)
{
  print_r($OrderEventDetailV["orderId"]);
}

Comments

0

Try this one

Array ( 
       [eventId] => "18345"
       [orderId] => "781" 
      )


Array ( 
      [eventId] => "18345"
      [orderId] => "781" 
       ) 

foreach($reportVal["OrderEventDetail"] AS $OrderEventDetailK => $OrderEventDetailV){
  $OrderEventDetailV["orderId"];
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.