Link to home
Start Free TrialLog in
Avatar of sabecs
sabecs

asked on

PHP - return count variable from function

Hi,
I am trying to keep count of the number of times 2 fields passed to my function match and then display the total,
I dont know what I am doing wrong but values are coming back as zero?

You comments and feedback would be appreciated.

<?php
 $match_yes = 0;
 $match_no = 0;

function check_match($profile_details, $user_details){
                  global $match_yes, $match_no;
                  
                  if ($profile_details == $user_details){
                  $match_yes++;
                  return '<img src="images/tick_sml.png" width="15" height="15" alt="Perfect Match" />';
                  return $match_yes;
                  
                  } else {
                  
                  $match_no++;            
                    return '<img src="images/cross_sml.png" width="15" height="15" alt="No Match" />';
                  return $match_no;      
            }

}
?>


<?php echo "You matched $match_yes times and did not match $match_no times" ;?>

<div class="user_details_heading">Gender:&nbsp;</div>
<div class="user_details_match"><?php echo check_match($row_view_users['match_gender'],$row_view_logged_in['gender']); ?></div>

<div class="user_details_heading">Hair Color:&nbsp;</div>
<div class="user_details_match"><?php echo check_match($row_view_users['match_hairColor'],$row_view_logged_in['hairColor']); ?></div>

<div class="user_details_heading">Hair Length:&nbsp;</div>
<div class="user_details_match"><?php echo check_match($row_view_users['match_hairLength'],$row_view_logged_in['hairLength']); ?></div>


ASKER CERTIFIED SOLUTION
Avatar of ramelong
ramelong
Flag of Argentina image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial