我有一個配對值(名稱和電子郵件)的數組,我試圖從一個正常的數組爲每兩個偏移量的關聯數組。例如:如何從正常數組的每兩個偏移量創建一個關聯數組?
Array
(
[0] => joe
[1] => [email protected]
[2] => bill
[3] => [email protected]
[4] => kyle
[5] => [email protected]
[6] => matt
[7] => [email protected]
[8] => chris
[9] => [email protected]
)
我想爲每個[$i]
& [$i+1]
關聯數組,所以它看起來像:
Array
(
[0] => Array
(
[name] => joe
[email] => [email protected]
)
[1] => Array
(
[name] => bill
[email] => [email protected]
)
)
我想:
$num = count($csvArray);
for ($i=0; $i < $num; $i+2) {
$newArray[] = array(
'name' => $csvArray[$i],
'email' => $csvArray[$i+1]
);
}
它給了我這個錯誤:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in C:\xampp\htdocs\array.php on line 20
我做錯了什麼?
'array.php'文件的第20行是什麼? – 2012-03-04 05:26:24