Skip to content

Instantly share code, notes, and snippets.

Created April 2, 2015 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/dbf2c873c4c06e8624ce to your computer and use it in GitHub Desktop.
Save anonymous/dbf2c873c4c06e8624ce to your computer and use it in GitHub Desktop.
<?php
$old = [
["id"=>1,'num'=>5,'period'=>35,'price'=>55],
["id"=>2,'num'=>10,'period'=>355,'price'=>5],
["id"=>3,'num'=>15,'period'=>9,'price'=>20]
];
$new = [];
foreach($old as $k => $v){
if(isset($new[$v['period']])){
$new[$v['period'] . $v['price']]['num'] += $v['num'];
}else{
unset($v['id']);
$new[$v['period'] . $v['price']] = $v;
}
}
var_dump($new);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment