Search code examples
phparraysforeach

Extracting data from specific subarray


I have the following array and I am trying to get data out of '[0]'.

Array (
  [ID] => 103088
  [key] => field_65002d05c4f14
  ... more elements
  [value] => Array (
    [0] => Array (
      [file_title] => Spec Sheet - with contents
      [file] => URL
    )
  )
  ... more elements
)

I have gone through to complete my foreach loop however I am getting no output - WordPress functions.php

foreach($arrayOBJ as $value => $file){
    //echo '<li><a href="'.$file['file'].'"></a>Some Text</li>';
}

I am expecting to be able to generate lines with "file" as the href and some text as the text.


Solution

  • Use:

    foreach($arrayOBJ['value'] as $file){
      //echo '<li><a href="'.$file['file'].'"></a>Some Text</li>';
    }