我想在我的数组中找到我的数组,但是当我尝试用我的neasted数组再次预测时,然后向我显示像Invalid argument supplied for foreach()
这样的错误,那么我该如何预测呢?
我的输出看起来像这样
low stock
Array
(
[0] => 4170
[1] => 4171
)
1
low stock
1500584174
我的功能
public function tests()
{
$array = $this->sale->get_all_cart($this->session->carrito);
foreach ($array as $key => $value) {
$product_id[] = $value['id'];
}
$entryData = array(
'message' => 'low stock',
'product_id' => $product_id,
'user_id' => 1,
'type' => 'low stock',
'timestamp' => time()
);
foreach ($entryData as $key => $value) {
echo "<pre>";
print_r ($value);
echo "</pre>";
}
}
答案 0 :(得分:0)
您必须在外部if
循环内创建一个foreach
块,并检查$key
是否为product_id
,以及$value
是否为foreach
数组与否。然后只循环使用另一个foreach
循环。
所以你的第二个// your code
foreach ($entryData as $key => $value) {
if($key == 'product_id' && is_array($value)){
foreach($value as $k => $v){
echo $k . " => " . $v . '<br />';
}
}else{
echo $key . " => " . $value . '<br />';
}
}
循环应该是这样的:
Dim wb As Workbook
Dim fileloc As String
fileloc = "" & "C:namenamename" & ".xlsm" & ""
Set wb = Workbooks.Open(fileloc)
wb.Worksheets("Sheet1").activate
wb.Close savechanges:=True