Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $a=Array(
- "0" => Array("jenis" => 'Buah',"deskripsi" => Array("0" => Array("name" => 'Jeruk',"pemasukan" => 20),"1" => Array("name" => 'Apel',"pemasukan" => 15))),
- "1" => Array("jenis" => 'Sayur',"deskripsi" => Array("0" => Array("name" => 'Bayam',"pemasukan" => 10),"1" => Array("name" => 'Wortel',"pemasukan" => 15))),
- "2" => Array("jenis" => 'Buah',"deskripsi" => Array("0" => Array("name" => 'Jeruk',"pemasukan" => 3),"1" => Array("name" => 'Apel',"pemasukan" => 25))),
- "3" => Array("jenis" => 'Sayur',"deskripsi" => Array("0" => Array("name" => 'Bayam',"pemasukan" => 31),"1" => Array("name" => 'Wortel',"pemasukan" => 13)))
- );
- $data=array();
- foreach($a as $k=>$v){
- foreach($v['deskripsi'] as $k1=>$v1){
- if(!isset($data[$v['jenis']])){
- $data[$v['jenis']]=array();
- }
- if(!isset($data[$v['jenis']][$v1['name']])){
- $data[$v['jenis']][$v1['name']]=$v1['pemasukan'];
- }else{
- $data[$v['jenis']][$v1['name']]+=$v1['pemasukan'];
- }
- }
- }
- print_r($data);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement