将另一组结果添加到数组中

发布于 2024-12-18 04:57:16 字数 721 浏览 0 评论 0原文

并不是百分百确定我在这里问的是什么。我想向我已经循环遍历的数组添加另一个级别。

$product_query = mysql_query("SELECT * FROM table");
while ($row = mysql_fetch_assoc($product_query)) {$products[] = $row;}
 foreach($products as $product){
  //external array request is here which then generates this:
  foreach ($Items->Item as $Items){
   echo $Items->title; // I want to add these value**s** to the existing $products array
  }
 }

所以我现在的想法是:

Array
(
    [0] => Array
        (
            [product_id] => 1
            [sku] => TPF1
        )

    [1] => Array
        (
            [product_id] => 2
            [sku] => TFL3
        )

我说得有道理吗?谢谢你的帮助

斯图

Not really 100% sure what I am asking here. I want to add another level to an array which I am already looping through.

$product_query = mysql_query("SELECT * FROM table");
while ($row = mysql_fetch_assoc($product_query)) {$products[] = $row;}
 foreach($products as $product){
  //external array request is here which then generates this:
  foreach ($Items->Item as $Items){
   echo $Items->title; // I want to add these value**s** to the existing $products array
  }
 }

So I currently have this:

Array
(
    [0] => Array
        (
            [product_id] => 1
            [sku] => TPF1
        )

    [1] => Array
        (
            [product_id] => 2
            [sku] => TFL3
        )

Am I making sense? Thank you for your help

Stu

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜心小果奶 2024-12-25 04:57:16
$product_query = mysql_query("SELECT * FROM table"); 
while ($row = mysql_fetch_assoc($product_query)) {$products[] = $row;} 
 foreach($products as &$product) { //notice the ambersand
     foreach ($Items->Item as $Item){ 
        $product['title'] =  $Item->title; 
  } 
}

现在 $products 将包含每个项目的标题

$product_query = mysql_query("SELECT * FROM table"); 
while ($row = mysql_fetch_assoc($product_query)) {$products[] = $row;} 
 foreach($products as &$product) { //notice the ambersand
     foreach ($Items->Item as $Item){ 
        $product['title'] =  $Item->title; 
  } 
}

now $products will containt each of the items title

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文