PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php function isHappy($string) { if ((int) $string % 2 === 0) {return false;}; $lenght = strlen($string); $middle = $string[$lenght / 2]; $part1 = substr($string, 0, $middle); $part2 = substr($string, $middle); $sum_part1 = array_sum(str_split($part1)); //9 $sum_part2 = array_sum(str_split($part2)); //15 print_r($part1); if ($sum_part1 === $sum_part2) { return true; } else { return false; } } $t = isHappy('34567'); print_r($t);
Show:  
Copy Clear