美好的一天!我被困住了,我对PHP多维数组还很陌生。 因此,我有两个搜索查询Query1用于查找Query2的值,我将每个查询都放置在多维数组中。
嵌套的foreach循环可以打印MultiArray的所有内容,但不能打印Marray
,我想在两个数组之间进行比较。
//FOR QUERY one results
$marray[$row['item_name']][$row['item_name']] = $row['item_name'];
$marray[$row['item_name']][$row['item_variant']] = $row['item_variant'];
$marray[$row['item_name']][$row['quantity']] = $row['quantity'];
//For Query two results
$multiarray[$row_inner['item_description']][$row_inner['item_description']]
= $row_inner['item_description'];
$multiarray[$row_inner['item_description']][$row_inner['item_variant']] =
$row_inner['item_variant'];
$multiarray[$row_inner['item_description']][$row_inner['end']] =
$row_inner['end'];
foreach($multiarray as $zz => $arrayz){
foreach($arrayz as $xx => $multi){
//echo "<script>console.log(\" ".$multi."\");</script>"; //shows multiarray result
echo "<script>console.log(\" ".$marray[$zz][$xx]."\");</script>"; //shows marray
}
}
var dump results
$marray
Array [size2]
Rose
Array [size3]
Rose
Red
1
Lily
Array [size3]
Lily
White
1
//
$multiarray
Array [size2]
Rose
Array [size3]
Rose
Red
20
Lily
Array [size3]
Lily
White
17
我想打印Marray的所有值,因为它不再显示最后一个值。只会打印出其颜色。
请帮助我并指导我确定其数量,谢谢!