So i’ve got an array that looks something like of:
Array ( [Safari] => 13 [Firefox] => 5 )
How do i a make a new array that looks like :
Array ( [Safari] => 72.2% [Firefox] => 27.7% )
using a neat php function?
thanks in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
array_sum()to get the total, then iterate over the values returning the new value.CodePad.
If you have >= PHP 5.3 it can be a tad more elegant with an anonymous function.
CodePad.