Skip to content

Instantly share code, notes, and snippets.

@reazul-islam
Last active January 5, 2022 08:01
Show Gist options
  • Select an option

  • Save reazul-islam/8134069c672a742a396103018eb2e5ea to your computer and use it in GitHub Desktop.

Select an option

Save reazul-islam/8134069c672a742a396103018eb2e5ea to your computer and use it in GitHub Desktop.
Problem solve PHP interview
<?php
function backwardsPrime($start, $stop)
{
$result = [];
for ($val = $start; $val <= $stop; $val++) {
if ((isPrimeCheck($val) && isPrimeCheck(strrev($val)) && $val != strrev($val))) {
$result[] = $val;
}
}
return $result;
}
function isPrimeCheck($num)
{
for ($i=2; pow($i, 2) <= $num; $i++) {
if ($num %$i == 0) {
return false;
}
}
return true;
}
function nbDig($n, $d)
{
$count = 0;
for ($i = 0; $i<= $n; $i++) {
$sqr = $i*$i;
$count += substr_count($sqr, (string)$d);
// $position = substr_count($sqr, (string)$d);
// if (!is_bool($position)) {
// echo $sqr.'<br>';
// }
//echo $i*$i .'<br>';
}
echo $count;
}
function solution($n)
{
$arr = [4=>7, 7=>4];
return array_search($n, $arr);
}
function parse($data)
{
$data = strtolower($data);
$value = 0;
$result = [];
for ($i=0; $i< strlen($data); $i++) {
$input = $data[$i];
if ($input == 'i') {
++$value;
} elseif ($input == 'd') {
--$value;
} elseif ($input == 's') {
$value *=$value;
} elseif ($input == 'o') {
$result[] = $value;
}
}
return $result;
}
function getAge($response)
{
// return correct age (int). Happy coding :)
$age = substr($response, 0, 1);
$age = (int)$age;
return $age;
}
function isPangram($string)
{
$string = preg_replace('/[^a-z]+/', '', strtolower($string));
$string = count_chars($string, 3);
return (strlen($string) == 26);
}
function getCount($str)
{
$vowelsCount = 0;
// enter your magic here
preg_match_all('/[aeiou]/i', $str, $matches);
return count($matches[0]);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment