Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $siswa = array
- (
- array (
- 'nama' => 'joko',
- 'kelas' => '3smp',
- 'hobi' => 'melukis'
- ),
- array (
- 'nama' => 'jokosableng',
- 'kelas' => '3smp',
- 'hobi' => 'menggambar'
- )
- );
- function array_trans_assoc($arr) {
- $out = array();
- foreach ($arr as $key => $sub_arr) {
- foreach ($sub_arr as $subkey => $subvalue) {
- $out[$subkey][$key] = $subvalue;
- }
- }
- return $out;
- }
- echo "<pre>";
- print_r(array_trans_assoc($siswa));
- /*---- RESULT:
- Array
- (
- [nama] => Array
- (
- [0] => joko
- [1] => jokosableng
- )
- [kelas] => Array
- (
- [0] => 3smp
- [1] => 3smp
- )
- [hobi] => Array
- (
- [0] => melukis
- [1] => menggambar
- )
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement