この配列を変換します。
Array
(
[0] => Array
(
[TEST] => Array
(
[name] => John Snow
[id] => 2
)
[HELLO] => Array
(
[stuff] => what
[more] => 0
)
)
[1] => Array
(
[TEST] => Array
(
[name] => Arya Stark
[id] => 3
)
[HELLO] => Array
(
[stuff] => dsfsdf dfsd
[more] => 3
)
)
[2] => Array
(
[TEST] => Array
(
[name] => Tyrion Lannister
[id] => 7
)
[HELLO] => Array
(
[stuff] => test
[more] => 2
)
)
)
に:
stdClass Object
(
[1] => stdClass Object
(
[TEST] => stdClass Object
(
[name] => John Snow
[id] => 2
)
[HELLO] => stdClass Object
(
[stuff] => what
[more] => 0
)
)
[2] => stdClass Object
(
[TEST] => stdClass Object
(
[name] => Arya Stark
[id] => 3
)
[HELLO] => stdClass Object
(
[stuff] => dsfsdf dfsd
[more] => 3
)
)
[3] => stdClass Object
(
[TEST] => stdClass Object
(
[name] => Tyrion Lannister
[id] => 7
)
[HELLO] => stdClass Object
(
[stuff] => test
[more] => 2
)
)
)
各レベル内に複数の配列を持つことができます。これは単なるダミー データであり、名前は決して TEST または HELLO ではなく、何でもかまいません。さらに情報が必要な場合はお知らせください。
これが私がこれまでに持っているものです:
function (&$data, $index) {
$object = new stdClass();
$output = array();
foreach ($data as $key => $value) {
$object->$key->$index = $value[$index];
}
return $object;
};