Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active August 26, 2020 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbvf50mobile/5c2f0b60fc064b1c48b25eecaabc3eca to your computer and use it in GitHub Desktop.
Save lbvf50mobile/5c2f0b60fc064b1c48b25eecaabc3eca to your computer and use it in GitHub Desktop.
Just PHP FUN 086.
<?php
# https://www.codewars.com/kata/58e2708f9bd67fee17000080 Numerical Palindrome #3.5.
function palindrome($num) {
if(!(is_int($num) && 0 <= $num)) return "Not valid";
$str = strval($num); $size = strlen($str);
$array = [];
for($i = 0; $i < $size; $i += 1)
for($j = 1; $j <= $size-$i; $j+=1){
$tmp = substr($str,$i,$j);
$x = intval($tmp); $z = intval(strrev($tmp));
if(strval($x) == strval($z) && $x > 10 && '0' != $tmp[0]) {
array_push($array,$x);
}
}
$array = array_unique($array); sort($array);
if(empty($array)) return "No palindromes found";
return $array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment