$result = [];
foreach ($arr as [$name, $price]) {
$result[$name] = [
'name' => $name,
'totalPrice' => ($result[$name]['totalPrice'] ?? 0) + $price,
'count' => ($result[$name]['count'] ?? 0) + 1
];
}
$result = array_values($result);
/*
array(2) {
[0] => array(3) {
["name"] => string(8) "iphone 0"
["totalPrice"] => int(156000)
["count"] => int(4)
}
[1] => array(3) {
["name"] => string(7) "macbook"
["totalPrice"] => int(300000)
["count"] => int(1)
}
}
*/
class Baz
{
public function bar() {
$this->foo();
}
public function foo() {
$backtrace = debug_backtrace();
$stack = array_map(
function($el) {
return "{$el['class']}{$el['type']}{$el['function']}";
},
$backtrace
);
var_dump($stack);
}
}
$t = new Baz;
$t->bar();
/* array(2) {
[0] => string(8) "Baz->foo"
[1] => string(8) "Baz->bar"
} */
$e = count($d) - 1;
$f = false;
$g = 0;
$h = 0;
if ($c < 0) {
$c = -$c;
$f = true;
}
$i = 2 / (2 + $c);
$j = 4 * $i - 2;
for (; $e > 0; $e--) {
$k = $g;
$g = $j * $g - $h + $d[$e];
$h = $k;
}
$l = $i * exp(-$c * $c + 0.5 * ($d[0] + $j * $g) - $h);
return $f ? ($l - 1) : (1 - $l);