$arr = [1,2,3,4,5,4,3,2,1];
$newarr = [];for($i = 0; $i<count($arr); $i++){ if(empty($newarr[$arr[$i]])){ $newarr[$arr[$i]] =1; }else{ $newarr[$arr[$i]]++; }
}
var_dump($newarr);