-1
請我有fowlloing代碼:如何操縱在PHP表
foreach($global as $item)
{
$item_array[] = array
(
'0' => value($this->elem[0], $item),
'1' => value($this->elem[1], $item),
'2' => value($this->elem[2], $item),
'3' => value($this->elem[3], $item),
'4' => value($this->elem[4], $item)
);
}
我想簡化它作爲folloing:
foreach($global as $item)
{
$i=0;
array_push($item_array[], value($this->elem[$i], $item));
$i++;
}
此代碼給了我一個arror因爲「$ item_array []「,這是我的腳本所必需的。我能做什麼 ?
注意:我對PHP很新手。謝謝。
在您的'array_push'調用中刪除'[]'。將元素添加到PHP數組(但未組合)時,可以使用'array_push',$ array []'或'$ array [index]'。 –
**它給你什麼**錯誤? – Mansfield
錯誤是:警告:array_push()期望參數1爲數組,空給出 –