我有一个像这样的多维数组:
Array
(
[0] => Array
(
[id] => 1
[name] => mail_failures_only
[value] => 0
)
[1] => Array
(
[id] => 2
[name] => default_service_ttl
[value] => 60
)
[2] => Array
(
[id] => 3
[name] => version
[value] => 5.0.0.0
)
[3] => Array
(
[id] => 4
[name] => process_all_jobs
[value] => 1
)
)
我想将“name”的每个值和“value”的每个值转换为关联数组,如下所示:
process_all_jobs => 1
如何为此构造循环?
我试过这样的事情:
$system_config_array = array();
if (is_array($configList)) {
$keys = array_keys($configList);
for($i = 0; $i < count($configList); $i++) {
foreach($configList[$keys[$i]] as $key => $value) {
echo $key . " : " . $value . "<br>";
if($key!='id')
$system_config_array[$value] = '';
}
}
}
其中$ configList是初始数组。
答案 0 :(得分:2)
答案 1 :(得分:2)
希望这会对你有所帮助:
$base = 'your array';
foreach ($base as $key => $value) {
$data[$value['name']] = $value['value'];
}
print_r($data);