PHP coding challenge
Throwing exceptions
⨠Your Task
Calculate and return the reciprocal of x (1 / x). If x is equal to zero throw an Exception with a message Division by zero.
āļø PHP PHP version: 8.1
š Press "Run" and check the result below.
Test cases
The reciprocal of 2 should be 0.5
Function should throw an Exception with a message Division by zero when calling with a value of zero.
Want to try another challenge?
- JavaScript
- Python
- PHP
- SQL
PHP Fundamentals
A set of coding problems that cover the basic syntax and features of the programming language.
1. VariablesComplexity
2. ConstantsComplexity
3. FunctionsComplexity
4. OperatorsComplexity
5. Control structuresComplexity
6. ArraysComplexity
7. StringsComplexity
8. Classes and ObjectsComplexity
9. NamespacesComplexity
10. Regular expressionsComplexity
11. Error handlingComplexity
12. MathComplexity