kjtocool Posted January 16, 2008 Share Posted January 16, 2008 I am writing a function which takes two arrays filled with movie name > movie gross pairs. The arrays are in no order, and the function will return a score for each movie, comparing the correct values in each array. I am not having a problem with the function, it works fine. But the line with comments above it is throwing an error when I try and add a new value to the array. <?php function get_user_scores($user_array, $actuals_array) { $array = array(); foreach ($user_array as $user_name => $user_gross) { foreach ($actuals_array as $actual_name => $actual_gross) { if ($user_name == $actual_name) { $difference = $user_gross - $actual_gross; $absolute = abs($difference); $score_unformated = $absolute / $actual_gross; $score = 1 - $score_unformated; $score = $score * 100; $score = round($score, 3); if ($score < 0) { $score = 0; } // This line (below) is throwing an error. $array[$user_name] = $score, $actual_gross; } } } return $array; } ?> Error: Parse error: syntax error, unexpected ',' in /home/worldofk/public_html/bonanza_results.php on line 269 Shouldn't this be a legal addition to an associative array? Quote Link to comment https://forums.phpfreaks.com/topic/86327-solved-associative-array-problem-w-multiple-values/ Share on other sites More sharing options...
paul2463 Posted January 16, 2008 Share Posted January 16, 2008 it does not understand the , between the two variables you would have to do it this way $array[$user_name] = array($score, $actual_gross); or $array[$user_name][0] = $score; $array[$user_name][1] = $actual_gross; Quote Link to comment https://forums.phpfreaks.com/topic/86327-solved-associative-array-problem-w-multiple-values/#findComment-441123 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.