0
Array ( [0] => Array ( [totalprice] => 671 [total] => 0 [price_per_p] => 2 ) [1] => Array ( [totalprice] => 312 [total] => 0 [price_per_p] => 2 ) )

Trying to get "totalprice" from each array.

$i = 0;
foreach($arr as $x_values => $x) {
   echo $x[$i]["totalprice"];
   $i++;
}

But this doesn't work at all.

$arr = array(
            array(
                "totalprice" => "671",
                "total" => "0",
                "price_per_p" => 2,
            ),
            array(
                "totalprice" => "312",
                "total" => "0",
                "price_per_p" => 2,
            )
        );

I'd like to get from array 1 at first "loop" and array 2 at second "loop"

sfsefsf33fs3fs3fs
  • 543
  • 3
  • 6
  • 17

1 Answers1

0

Just remove $i index. No need $i variable.

//$i = 0;
foreach($arr as $x_values => $x) {
   echo $x["totalprice"];
   //$i++;
}
Naga
  • 2,190
  • 3
  • 16
  • 21