我想兩個數組與PHP的array_combine()
功能結合起來,我收到此錯誤:array_combine()預計參數1是數組,字符串給出
array_combine() expects parameter 1 to be array, string given
的$科目的var_dump表明這一點:
array(
(int) 0 => 'English',
(int) 1 => 'Mathematics',
(int) 2 => 'Biology',
(int) 3 => 'Physics',
(int) 4 => 'Chemistry'
)
的$定製顯示此的var_dump:
array(
(int) 0 => array(
'score' => '72',
'grade' => 'B+',
'points' => '10'
),
(int) 1 => array(
'score' => '99',
'grade' => 'A',
'points' => '12'
),
(int) 2 => array(
'score' => '77',
'grade' => 'A-',
'points' => '11'
),
(int) 3 => array(
'score' => '50',
'grade' => 'C+',
'points' => '7'
),
(int) 4 => array(
'score' => '66',
'grade' => 'B+',
'points' => '10'
)
)
功能:
function score($received,$arr) {
$keys = $received;
$data_set = array_combine($keys,$arr);
return $data_set;
}
這裏就是我所說的功能:
$data_set = array_map(array($this->Scores,'score'),$subjects ,custom);
如果調試顯示所有的變量數組:爲什麼$科目出現作爲字符串array_combine?
編輯:
預期輸出
array(
'English' => array(
'score' => '72',
'grade' => 'B+',
'points' => '10'
),
'Mathematics' => array(
'score' => '99',
'grade' => 'A',
'points' => '12'
),
'Biology' => array(
'score' => '77',
'grade' => 'A-',
'points' => '11'
),
'Physica' => array(
'score' => '50',
'grade' => 'C+',
'points' => '7'
),
'Chemistry' => array(
'score' => '66',
'grade' => 'B+',
'points' => '10'
)
)
會是什麼預期的輸出?我想你只是想做到這一點:'$ data_set = array_combine($ subjects,$ custom);'你不需要array_map,否則你循環$ subject的每個元素,然後是我編輯的字符串 – Rizier123 2015-04-05 15:53:08
@ Rizier123包括預期產出 – GOA 2015-04-05 15:57:22