0

I have an array that looks like this:

Array (
  [0] => 
    Array ( 
        [id] => 3434 
        [label] => some test label
    ) 
)

I need to get the ids and the labels from this array. so i tried this:

foreach($results['id'] as $result) { echo $result['label'], '<br>'; }

but this doesn't do anything and it gives me this error:

PHP Notice: Undefined index: id in

Could someone please advice on this issue?

Thanks in advance.

ryantxr
  • 4,119
  • 1
  • 11
  • 25
James Juanjie
  • 219
  • 3
  • 18

2 Answers2

0

Try

 foreach($your_array as $temp){
   echo $temp["id"];
   echo $temp["label"];
}
MalcolmInTheCenter
  • 1,376
  • 6
  • 27
  • 47
0

It's multidimensional array. You can get Id and label value from array like this:

foreach($results as $result) 
{
    echo $result['label'].'<br>';
    echo $result['id'].'<br>';
}