I would like to perform the following server-side in PHP…
If I have one array like this: $array1 = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), can I create another array which contains the percent of each value (each value divided by the total)? Is there a way to do this without brute forcing with a for loop? I essentially want to create array2
sum_array($array1) produces 55 (1+2+3+4+5+6+7+8+9+10 = 55)
$array2 = array(1.8%, 3.6%, 5.4%, 7.2%, 9%, 10.9%, 12.7%, 15.5%, 16.3%, 18.2%)
Thanks in advance
You can use
array_mapfor this.