I'm trying to combine two arrays with PHP's array_combine() function and I receive this error:
array_combine() expects parameter 1 to be array, string given
var_dump of $subjects shows this:
array(
(int) 0 => 'English',
(int) 1 => 'Mathematics',
(int) 2 => 'Biology',
(int) 3 => 'Physics',
(int) 4 => 'Chemistry'
)
var_dump of $custom show this:
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:
function score($received,$arr) {
$keys = $received;
$data_set = array_combine($keys,$arr);
return $data_set;
}
Here is where I call the function:
$data_set = array_map(array($this->Scores,'score'),$subjects ,custom);
if the debug shows all the variables as arrays: why is $subjects appearing as string to array_combine?
EDIT:
expected output
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);You don't need array_map otherwise you loop through each element of $subjects, which then are strings