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
  • 3,926
  • 1
  • 10
  • 24
James Juanjie
  • 189
  • 14

2 Answers2

0

Try

 foreach($your_array as $temp){
   echo $temp["id"];
   echo $temp["label"];
}
MalcolmInTheCenter
  • 1,140
  • 5
  • 21
  • 41
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>';
}