Skip to content

Instantly share code, notes, and snippets.

@MohcinBN
Last active May 18, 2022 17:35
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 MohcinBN/1efb1f3d7e460e29e18039af5c633fd8 to your computer and use it in GitHub Desktop.
Save MohcinBN/1efb1f3d7e460e29e18039af5c633fd8 to your computer and use it in GitHub Desktop.
Find Numbers with Even Number of Digits
<?php
$nums = [6, 12];
function findNumbers($nums) {
// initialise the count
$count = 0;
foreach($nums as $num){
$numLenght = strlen($num);
//check the array lenght if modulo
if($numLenght % 2 == 0) {
// count increments
$count++;
}
}
return $count;
}
// call the function
echo findNumbers($nums);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment