Advertisement
Pass89

array_multi_18-10-21

Oct 17th, 2021 (edited)
1,461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1. <?php
  2. // data awal
  3. $sample = array(
  4.             array(
  5.                 'p3' => 'A',
  6.                 'p4' => 'B',
  7.                 'p6' => 'C'
  8.             ),
  9.             array(
  10.                 'p3' => 'B',
  11.                 'p4' => 'B',
  12.                 'p6' => 'C'
  13.             ),
  14.             array(
  15.                 'p3' => 'B',
  16.                 'p4' => 'B',
  17.                 'p6' => 'B'
  18.             )
  19.         );
  20. print_r($sample);
  21.  
  22. // output yg diinginkan
  23. $result = array(
  24.             'p3' => array(
  25.                 '0' => 'A',
  26.                 '1' => 'B',
  27.                 '2' => 'B'
  28.             ),
  29.             'p4' => array(
  30.                 '0' => 'B',
  31.                 '1' => 'B',
  32.                 '2' => 'B'
  33.             ),
  34.             'p6' => array(
  35.                 '0' => 'C',
  36.                 '1' => 'C',
  37.                 '2' => 'B'
  38.             )
  39.         );
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement