How to get the values from a multi dimension array
I have a result from my db query that's look like this when dump and the
query is doing what is expected, bu I am have a little problem getting the
array values. I am using PHP PDO to get the result.
$result = $_stmt->fetchAll();
$row = count($result);
print_r($result);
Array ( [0] => Array ( [SUM(od_price * od_qty)] => 69.85 [0] => 69.85 )
[1] => Array ( [SUM(od_price * od_qty)] => 13.97 [0] => 13.97 )
) 69.8513.97
You can see that the result contains both an array and a string values. I
have an option to get either the array or the string value. But I would
rather to get the array values since the the string values are all
togather. Can some one please explain what I am doing that's wrong in the
foreach loop?
if($row == 2)
{
foreach ($result as $k)
{
echo $price_1 = $k[0][0]; // expected 69.85
echo $price_2 = $k[0][1]; // expected 13.97
}
unset($k);
}
I need to get the expected values, but instead I am getting the string
values that are all togather.
No comments:
Post a Comment