The following function does not return any value when if statement is true; otherwise it is returning $var1
; it shows the correct value.
function setValue($var1) {
global $con;
global $k;
$k++;
$var1 = strtolower($var1);
$var1 = preg_replace('/[^a-zA-Z0-9_-]/', '-', $var1);
$var1 = preg_replace('/-+/', '-', $var1);
$result1 = mysqli_query($con, "select * from tbl_name where name='".$var1."'");
if (mysqli_num_rows($result1) > 0) {
setValue($var1.'-'.$k);
}
else {
//die($var1);
return $var1;
}
}