我有一个这样的数组:
0 => array:8 [▼
"_id" => MongoId {#266 ▶}
"name" => "New param"
"default" => "900"
"visibility" => "1"
"type" => 1
"only_numbers" => "1"
"value" => "900"
"available" => "1"
]
如何将此数组折叠为:
$arr["New param"] = "900";
仅限:
$arr = array(
$a["name"] => $a["value"]
);
答案 0 :(得分:3)
看起来您的数组是另一个数组的元素(顶部隐含的$arr[$a[0]['name']] = $a[0]['value'];
)。所以你需要索引包含数组:
foreach ($a as $el) {
$arr[$el['name']] = $el['value'];
}
如果要获取其他数组的所有元素,请使用循环:
$arr = array_combine(array_column($a, 'name'), array_column($a, 'value'));
或者你可以这样做:
UPDATE task
JOIN (SELECT ts.t_id
FROM subtask s
JOIN task_subtask ts ON s.s_id = ts.s_id
GROUP BY ts.t_id
HAVING COUNT(s.s_id) = SUM(s.done)
) x
ON task.t_id = x.t_id
SET all_done = 1