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_detai ls, $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_headin g">Gender: </di v>
<div class="user_details_match" ><?php echo check_match($row_view_user s['match_g ender'],$r ow_view_lo gged_in['g ender']); ?></div>
<div class="user_details_headin g">Hair Color: </div>
<div class="user_details_match" ><?php echo check_match($row_view_user s['match_h airColor'] ,$row_view _logged_in ['hairColo r']); ?></div>
<div class="user_details_headin g">Hair Length: </div>
<div class="user_details_match" ><?php echo check_match($row_view_user s['match_h airLength' ],$row_vie w_logged_i n['hairLen gth']); ?></div>
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_detai
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"
return $match_no;
}
}
?>
<?php echo "You matched $match_yes times and did not match $match_no times" ;?>
<div class="user_details_headin
<div class="user_details_match"
<div class="user_details_headin
<div class="user_details_match"
<div class="user_details_headin
<div class="user_details_match"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.