0

The array prints out like this:

object(Postmaster_Rates)#2 (1) { ["_values:protected"]=> array(3) { ["currency"]=> string(3) "USD" ["charge"]=> int(580) ["service"]=> string(6) "GROUND" } }

How would I display this in a "nicer" form using foreach in php.

I tried this: (but it didn't echo out anything.)

foreach($result as $rate){
  echo $rate['service'];
}
user2948950
  • 137
  • 1
  • 4
  • 13

3 Answers3

0

It's an array of "objects" you call it like echo $rate->service

s3nzoM
  • 1,544
  • 1
  • 9
  • 17
0

Do you need to use foreach? You could also try: $array = (array) $yourObject;

From http://www.php.net/manual/en/language.types.array.php

Seff
  • 217
  • 1
  • 9
0

Take a look at this at these two options.

// Cast to an array
$array = (array) $object;

// get_object_vars
$array = get_object_vars($object);

There are several answers here that can show you.

https://stackoverflow.com/a/2476954/330987

Community
  • 1
  • 1
Panama Jack
  • 24,158
  • 10
  • 63
  • 95