0

I have an array coming into my PHP function that looks like this:

Array
(
    [BULD-FAX] => 5.00
)

The string BULD-FAX is dynamic and not known until runtime. I'm simply trying to get the dollar value, which in this case is 5.00.

Here's my code:

$productName = key($myArray);
$amount =  $myArray[$productName]->{0};

$productName evaluates to BULD-FAX as expected. But $amount is blank. What am I doing wrong?

HerrimanCoder
  • 6,835
  • 24
  • 78
  • 158

1 Answers1

0

There is likely a better way to do it, but you could do a loop that would only execute one time (in the case of your example). It would look like this:

foreach ($myArray as $key => $value) {
    $productName = $key;
    $amount =  $value;
//do something here with the values if there are more than one item in the array
}
mtr.web
  • 1,505
  • 1
  • 13
  • 19