如何使用foreach提取PHP变量中的数组数据?

如何使用foreach提取PHP变量中的数组数据?,php,Php,我需要提取php中变量的最后一个数组数据,即SiteName、Url、Title array 'ApplicableProductOfferings' => array 0 => string 'EasyDemo' (length=10) 'Artist' => string 'Hello' (length=10) 'ReferralDestinations' => array 0 => array

我需要提取php中变量的最后一个数组数据,即SiteName、Url、Title



array
  'ApplicableProductOfferings' => 
    array
      0 => string 'EasyDemo' (length=10)
  'Artist' => string 'Hello' (length=10)
  'ReferralDestinations' => 
    array
      0 => 
        array
          'SiteName' => string 'gettyimages' (length=11)
          'Url' => string 'http://www.gettyimages.com/detail/160414706' (length=43)
          'Title' => string 'Pixie Lott Launches The New BlackBerry Z10' (length=42)
          'UrlComp' => string 'http://localhost.com' (length=197)
          'UrlPreview' => string 'http://localhost.com' (length=164)
          'UrlThumb' => string 'http://localhost.com' (length=82)
          'UrlWatermarkComp' => string 'http://localhost.com' (length=197)
          'UrlWatermarkPreview' => string 'http://localhost.com
试试这个

   foreach($data as $dat)
   {
       foreach($dat['ReferralDestinations'] as $key => $d) 
        {
           echo $d['SiteName'];
           echo $d['Url'];
           echo $d['Title'];
        }
    }

这取决于在阵列中存储数据的方式。如果您有一个已经包含最后一个数组数据的数组,那么它非常简单

foreach ($myArray as $var) {
  echo $var;
}
或者访问单个元素,如$myArray['SiteName']、$myArray['Url']等

假设上述数据位于一个名为$arrayOfArrays的数组中

foreach ($arrayOfArrays as $myArray) {

  // $myArray now holds first array, second array etc as the loop is executed
  // First time it holds 'ApplicableProductOfferings', second time 'ReferralDesinations'..

  // If the array is 'ReferralDesitnations' you can loop through that array
  // to get the elements you are looking for SiteName etc as below

  foreach ($myArray as $URLElement) {
    echo $URLElement;
  }
}
//extract()标志=>EXTR\u如果存在。。。
//

你试过什么吗?
$array1 = [];
$array2 = [];

foreach ($array1 as $key=> $val) {
extract($array2, EXTR_IF_EXISTS, $val);
}