0

我需要提取最后一个数组数据,即站点名称、网址、标题到 php 中的变量。



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
4

3 回答 3

0

这取决于您如何将数据存储在数组中。如果你有一个已经有最后一个数组数据的数组,那就很简单了。

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;
  }
}
于 2013-02-07T07:27:24.893 回答
0

尝试这个.......

   foreach($data as $dat)
   {
       foreach($dat['ReferralDestinations'] as $key => $d) 
        {
           echo $d['SiteName'];
           echo $d['Url'];
           echo $d['Title'];
        }
    }
于 2013-02-07T07:08:29.820 回答
0
$array1 = [];
$array2 = [];

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

// extract() 标志 => EXTR_IF_EXISTS ... // http://php.net/manual/ru/function.extract.php

于 2019-01-12T11:39:49.610 回答