gpt4 book ai didi

php - array_combine() 期望参数 1 为数组,字符串给定

转载 作者:搜寻专家 更新时间:2023-10-31 21:31:35 24 4
gpt4 key购买 nike

<分区>

我正在尝试使用 PHP 的 array_combine() 函数组合两个数组,但我收到此错误:

array_combine() expects parameter 1 to be array, string given

$subjects 的 var_dump 显示:

array(
(int) 0 => 'English',
(int) 1 => 'Mathematics',
(int) 2 => 'Biology',
(int) 3 => 'Physics',
(int) 4 => 'Chemistry'
)

$custom 的 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);

如果调试将所有变量显示为数组:为什么 $subjects 显示为 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'
)
)

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com