我有一个下面的数组,它是我从Rubrics表中得到的,我正在使用一个jquery扩展,它给了我下面的数组:
Array
(
[1] => Array
(
[0] => Identifies Dilemma
[1] => Has a vague idea of what the dilemma is and is uncertain what must be decided
[2] => Identifies the dilemma, including pertinent facts, and ascertains what must be decided
[3] => Describes the dilemma in detail having gathered pertinent facts. Ascertains exactly what must be decided
)
[2] => Array
(
[0] => Considers Stakeholders
[1] => Is unsure as to who should be involved in the decision-making process
[2] => Determines who should be involved in the decision-making process and accurately identifies all the stakeholders
[3] => Determines who should be involved in the decision-making process and thoroughly reflects on the viewpoints of the stakeholders
)
)我尝试获取的输出是:-
[
'Identifies Dilemma' => [
[1] => Has a vague idea of what the dilemma is and is uncertain what must be decided
[2] => Identifies the dilemma, including pertinent facts, and ascertains what must be decided
[3] => Describes the dilemma in detail having gathered pertinent facts. Ascertains exactly what must be decided
]
],
[
'Considers Stakeholders' => [
[1] => Is unsure as to who should be involved in the decision-making process
[2] => Determines who should be involved in the decision-making process and accurately identifies all the stakeholders
[3] => Determines who should be involved in the decision-making process and thoroughly reflects on the viewpoints of the stakeholders
]
]这是我到目前为止已经尝试过的,但如果一些php函数可以帮助我,我不想在很多情况下使用它。
$rubics = json_decode($model->rubric_json);
$originalPoints = json_decode($model->points_json)[0];
$rubicsCols = json_decode($model->rubric_json)[0];
unset($rubics[0]);
if (!empty($rubics)) {
foreach ($rubics as $key => $data) {
$rows[] = $data[0];
}
}
echo "<pre>";
print_r($rubics);exit;发布于 2020-07-15 21:40:02
$arr = [
['a','b','c'],
['a1','b1','c1']
];
$newArray = [];
foreach ($arr as $key => $data) {
$newKey = $data[0];
unset($data[0]);
$newArray[$newKey] = $data;
}
print_r($newArray);输出:
Array
(
[a] => Array
(
[1] => b
[2] => c
)
[a1] => Array
(
[1] => b1
[2] => c1
)
)https://stackoverflow.com/questions/62916102
复制相似问题