Last active
May 18, 2022 17:35
-
-
Save MohcinBN/1efb1f3d7e460e29e18039af5c633fd8 to your computer and use it in GitHub Desktop.
Find Numbers with Even Number of Digits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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