4

我正在追赶我的尾巴,试图将两个不同查询的结果组合到一个模板中输出。

我正在尝试合并model_data和entry_data中的相应子数组以获得desired_result。然后我将遍历 desired_result 并将值打印到模板中。

非常感谢任何帮助。

模型数据

array(2) {
  [0]=>
  array(2) {
    ["entry_id"]=> string(3) "192"
    ["field_id_49"]=> string(10) "Model Name"
  }
  [1]=>
  array(2) {
    ["entry_id"]=> string(3) "193"
    ["field_id_49"]=> string(5) "MN123"
  }
}

入口数据

array(2) {
  [0]=>
  array(2) {
    ["uri"]=> string(24) "/products/product-title/"
    ["title"]=> string(13) "Product Title"
  }
  [1]=>
  array(2) {
    ["uri"]=> string(22) "/products/lorem-ipsum/"
    ["title"]=> string(11) "Lorem Ipsum"
  }
}

期望的结果

array(2) {
  [0]=>
  array(4) {
    ["entry_id"]=> string(3) "192"
    ["field_id_49"]=> string(10) "Model Name"       
    ["uri"]=> string(24) "/products/product-title/"
    ["title"]=> string(13) "Product Title"      
  }
  [1]=>
  array(4) {
    ["entry_id"]=> string(3) "193"
    ["field_id_49"]=> string(5) "MN123"      
    ["uri"]=> string(22) "/products/lorem-ipsum/"
    ["title"]=> string(11) "Lorem Ipsum"
  }
}
4

1 回答 1

8
foreach($model_data as $key => $value){
    $result[$key] = array_merge($entry_data[$key], $model_data[$key]);
}
于 2011-09-27T21:10:49.590 回答