0

Just a quick one..

While running through a multi-array array in a loop. How do I check the head value.. Not sure if I can explain it properly. but here is the array:

Array
(
    [SMS] => Array
        (
            [VoucherCode] => V510
            [VoucherName] => 2000 SMS
            [VoucherAmount] => 450
            [IsPinless] => 1
        )

    [DATA] => Array
        (
            [VoucherCode] => V549
            [VoucherName] => 150MB
            [VoucherAmount] => 29
            [IsPinless] => 1
        )

    [AIRTIME] => Array
        (
            [VoucherCode] => V500
            [VoucherName] => Pinless
            [VoucherAmount] => -1
            [IsPinless] => 1
        )
)

So How can I see the "SMS" or "DATA" value in a loop to check if I need to add to that section of the array?

What I have thats not working

foreach($GroupArray as $item) {
    if ($item == 'SMS'){
           //Do Stuff..
    }
}

1 Answers1

4

Change your code to look like following:

foreach($GroupArray as $key => $value) {
    if ($key == 'SMS'){
           //Do Stuff..
    }
}
oreopot
  • 3,392
  • 2
  • 19
  • 28