Write a PHP program to check a positive integer and return true if it contains a number 2.
<?php function test($n) { while ($n > 0) { if ($n % 10 == 2) return true; $n /= 10; } return false; } var_dump(test(123)); var_dump(test(13)); var_dump(test(222));
Sample Output:
bool(true) bool(false) bool(true)
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer