Advertisement
cdsatrian

buah dan sayur

Apr 10th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. <?php
  2. $a=Array(
  3. "0" => Array("jenis" => 'Buah',"deskripsi" => Array("0" => Array("name" => 'Jeruk',"pemasukan" => 20),"1" => Array("name" => 'Apel',"pemasukan" => 15))),
  4. "1" => Array("jenis" => 'Sayur',"deskripsi" => Array("0" => Array("name" => 'Bayam',"pemasukan" => 10),"1" => Array("name" => 'Wortel',"pemasukan" => 15))),
  5. "2" => Array("jenis" => 'Buah',"deskripsi" => Array("0" => Array("name" => 'Jeruk',"pemasukan" => 3),"1" => Array("name" => 'Apel',"pemasukan" => 25))),
  6. "3" => Array("jenis" => 'Sayur',"deskripsi" => Array("0" => Array("name" => 'Bayam',"pemasukan" => 31),"1" => Array("name" => 'Wortel',"pemasukan" => 13)))
  7. );
  8. $data=array();
  9. foreach($a as $k=>$v){
  10.   foreach($v['deskripsi'] as $k1=>$v1){
  11.     if(!isset($data[$v['jenis']])){
  12.       $data[$v['jenis']]=array();
  13.     }
  14.     if(!isset($data[$v['jenis']][$v1['name']])){
  15.       $data[$v['jenis']][$v1['name']]=$v1['pemasukan'];
  16.     }else{
  17.       $data[$v['jenis']][$v1['name']]+=$v1['pemasukan'];
  18.     }
  19.   }
  20. }
  21. print_r($data);
  22. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement