html - How do I create a PHP function to output values from different variables when called? -
i have different variables arrays different values. need display values of each array item in html, know how do. problem is, need find percentage of values of each array item in relation themselves. equation like: blue balls percentage = blue balls / sum of array items * 100 i'm way use function in order echo results of each array item through equation, have no idea how write it. this arrays: $balls = array( 'red' => 5, 'blue' => 7, 'green' => 2 ); $socks = array( 'red' => 5, 'blue' => 7, 'green' => 2 ); this think html should like: blue balls make up<?php echo $percent($ball['blue']); ?>% of balls. there <?php echo $balls['blue']; ?> blue balls. i'm trying achieve final result: blue balls make 50% of balls. there 7 blue balls. i know bottom echo valid, have no idea how attempt write function top echo, or if echo possible. <?ph