
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
PHP program to check if all digits of a number divide it
To check if all digits of a number divide it in PHP, the code is as follows −
Example
<?php function divisibility_check($my_val, $my_digit) { return ($my_digit != 0 && $my_val % $my_digit == 0); } function divide_digits($n) { $temp = $my_val; while ($temp > 0) { $my_digit = $my_val % 10; if (!(divisibility_check($my_val, $my_digit))) return false; $temp /= 10; } return true; } $val = 255; if (divide_digits($val)) echo "All the numbers can be divided"; else echo "All the numbers can't be divided"; ?>
Output
All the numbers can be divided
A function named ‘divisibility_check’ is defined that checks to see if the number is not 0 and if the number completely divides every digit of the number, without leaving any value as a remainder. Another function named ‘divide_digits’ is defined that checks to see if every digit in the number divides the number completely. The number is defined, and the ‘divide_digits’ function is called by passing this number as the parameter. Relevant message is displayed on the console.
- Related Articles
- C Program to Check if all digits of a number divide it
- Java Program to check if all digits of a number divide it
- Python Program for Check if all digits of a number divide it
- Check if all digits of a number divide it in Python
- C++ Program to check if a given number is Lucky (all digits are different)
- C Program to check if a number is divisible by sum of its digits
- C Program to check if a number is divisible by any of its digits
- PHP program to check if a number is prime or not
- PHP program to sum the digits in a number
- Check if the frequency of all the digits in a number is same in Python
- Python Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- Java Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- PHP program to check if the total number of divisors of a number is even or odd
- C/C++ Program to check whether it is possible to make a divisible by 3 number using all digits in an array?
- Java Program To Reverse A Number And Check If It Is A Palindrome Number

Advertisements