0

我正在尝试向 foreach 循环中的每一行添加另一列数据。它的目的是记住从 XML 处理到多维数组中导入的数据元素。尽管 var_dumps 看起来不错,但它仍然是一个标量。

<?php 
$KEY = 0;
foreach ($eventsArray as $keyMe){
  $thisKey['KEY'][0] = strval($KEY);
  $keyedArray = array_merge($keyMe, $thisKey);
$KEY++;
}

// Prep for multisort
foreach ($keyedArray as $key => $value){
  $date[$key] = $value['DATE'];
  $title[$key] = $value['TITLE'];
  $link[$key] = $value['LINK'];
  $slide[$key] = $value['SLIDE'];
  $location[$key] = $value['LOCATION'];
  $time[$key]= $value['TIME'];
  $KEY[$key] = $value['KEY']; // Warning: Cannot use a scalar value as an array
}

/* var_dump(
array(7) { 
  ["DATE"]=> array(1) { [0]=> string(10) "2012-12-18" } 
  ["TITLE"]=> array(1) { [0]=> string(20) "Event Title" } 
  ["LINK"]=> array(1) { [0]=> string(38) "aLinkLocation.htm" } 
  ["SLIDE"]=> array(1) { [0]=> string(2) "16" } 
  ["LOCATION"]=> array(1) { [0]=> string(8) "Location of Event" } 
  ["TIME"]=> array(1) { [0]=> string(3) "8am" } 
  ["KEY"]=> array(1) { [0]=> string(2) "23" } 
} 
*/
4

0 回答 0