Arrays 在laravel 4上迭代循环(更新)
你好 为什么我在laravel 4中迭代循环时出错?以下是我控制器上的代码: 当我试图:Arrays 在laravel 4上迭代循环(更新),arrays,laravel,laravel-4,Arrays,Laravel,Laravel 4,你好 为什么我在laravel 4中迭代循环时出错?以下是我控制器上的代码: 当我试图: $input = Input::get('product'); echo "<pre>"; dd($input); 但当我尝试遍历循环时,我的代码如下: <input name="name"/> <input name="items[0][description]"/> <input name="items[0][itemId]"/> <input
$input = Input::get('product');
echo "<pre>";
dd($input);
但当我尝试遍历循环时,我的代码如下:
<input name="name"/>
<input name="items[0][description]"/>
<input name="items[0][itemId]"/>
<input name="items[0][description]"/>
<input name="items[0][quantity]"/>
<input name="items[0][poContentId]"/>
<input name="items[0][price]"/>
<input name="items[1][description]"/>
<input name="items[1][itemId]"/>
<input name="items[1][description]"/>
<input name="items[1][quantity]"/>
<input name="items[1][poContentId]"/>
<input name="items[1][price]"/>
我得到未定义的索引:poContentId
错误
我想在这里做一个批量更新,你能看看我的代码吗,我不知道我在这里遗漏了什么。谢谢你的指导 您的数组构造得不好。您有3个索引:
”
、0
和1
。在第一个索引中,只有一个小数组,只有名称索引,没有poContentId
,这就是为什么会出现错误
在您的表单中,您必须这样编写输入:
$items = Input::get('items');
foreach ( $items as $v ) {
dd($v['poContentId']);
}
数组中的第一个元素没有poContentId
键。感谢您的回答!我已经弄明白了!我渲染了
<input name="name"/>
<input name="items[0][description]"/>
<input name="items[0][itemId]"/>
<input name="items[0][description]"/>
<input name="items[0][quantity]"/>
<input name="items[0][poContentId]"/>
<input name="items[0][price]"/>
<input name="items[1][description]"/>
<input name="items[1][itemId]"/>
<input name="items[1][description]"/>
<input name="items[1][quantity]"/>
<input name="items[1][poContentId]"/>
<input name="items[1][price]"/>
$items = Input::get('items');
foreach ( $items as $v ) {
dd($v['poContentId']);
}