Php 将另一组结果添加到数组中
不是100%确定我在问什么。我想在我已经循环的数组中添加另一个级别Php 将另一组结果添加到数组中,php,arrays,multidimensional-array,Php,Arrays,Multidimensional Array,不是100%确定我在问什么。我想在我已经循环的数组中添加另一个级别 $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 thi
$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
)
我说得通吗?谢谢你的帮助
斯图
现在$products将包含每个项目标题是否希望$products->title附加到$product?是的,假设每个现有产品中添加3个标题。看起来它的格式不正确:[5]=>数组([product_id]=>6[sku]=>TL9[0]=>SimpleXMLElement对象([0]=>title1)[1]=>SimpleXMLElement对象([0]=>title2])是$Item->title对象。你可以发布一个$itemsimplexmlement对象([title]=>title1)的打印吗?我需要将xml结果转换为数组吗?需要使用strval($Item->title);
$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;
}
}