11

I want to access the index 'memo' in the associative array in PHP below

$variables["thelistitems"];
print_r($variables["thelistitems"]);

Output

Array
(
    [0] => Array
    (
        [productid] => prod:c6dbdd62-dc13-6421-5a94-c8cd871a59d3 
        [memo] => dummy 
        [taxable] => 0 
        [unitweight] => 0 
        [unitcost] => 450.02 
        [unitprice] => 445.02 
        [quantity] => 1
    )
) 
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
slao
  • 1,986
  • 7
  • 27
  • 37

2 Answers2

25

What you essentially have is an array of associative arrays. So to access the first memo, it's

 $variables["thelistitems"][0]["memo"]

To access each memo, you'd do something like this

foreach($variables["thelistitems"] as $listitem) {
    $memo = $listitem["memo"];
}
villecoder
  • 13,323
  • 2
  • 33
  • 52
3

Do you want this ?

$variables["thelistitems"][0]['memo']
Loïc Février
  • 7,540
  • 8
  • 39
  • 51