3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = array( 0 => 2, 1 => 3, 2 => 10, 3 => 3, 4 => 4, 5 => 8, 6 => 5, 7 => 1, 8 => 1 ); $b = array( 0 => "Hello world poduct", 1 => "Test Product", 2 => "Hello world poduct", 3 => "Hello world poduct", 4 => "Test Product", 5 => "Test Product", 6 => "Test Product", 7 => "Test Product", 8 => "Test Product", ); #for usage $result = []; for($i=0;$i<count($a);$i++){ if(!isset($result[$b[$i]])){ $result[$b[$i]] = 0; } $result[$b[$i]] += $a[$i]; } var_export($result); #array_walk $result = []; array_walk($a,function($v,$i) use (&$result,$b) { if(!isset($result[$b[$i]])){ $result[$b[$i]] = 0; } $result[$b[$i]] += $v; }); echo PHP_EOL; var_export($result);

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
155.71 ms | 1744 KiB | 10 Q