[data] => Array
(
[1] => Array
(
[text] => Array
(
[0] => link1
[1] => link2
)
[active] => Array
(
[0] => 1
[1] => 1
)
[id] => Array
(
[0] => 0
[1] => 0
)
)
)
[data] => Array
(
[1] => Array
(
[0] => Array
(
[text] => link1
[active] => 1
[id] => 0
)
[1] => Array
(
[text] => link2
[active] => 1
[id] => 0
)
)
)
$keys = array();
foreach ($data as $item) {
$keys = array_fill_keys(array_keys($item),(object)array());
// ...
}
$result = array_fill_keys(array_keys($data),array());
foreach ($data as $data_key => $data_item) {
foreach ($data_item as $key => $values) {
foreach ($values as $value_key => $value_val) {
if (!isset($result[$data_key][$value_key])) {
$result[$data_key][$value_key] = (object)array();
}
$result[$data_key][$value_key]->$key = $value_val;
}
}
}
$data = array_map(
function ($data) {
$result = [];
foreach ($data as $field => $values) {
foreach ($values as $index => $value) {
if (!isset($result[$index])) {
$result[$index] = [];
}
$result[$index][$field] = $value;
}
}
return $result;
},
$data
);