PHP Exercises, Practice, Solution
What is PHP?
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.
The best way we learn anything is by practice and exercise questions. We have started this section for those (beginner to intermediate) who are familiar with PHP.
Hope, these exercises help you to improve your PHP coding skills. Currently, following sections are available, we are working hard to add more exercises. Happy Coding!
Note: It's fine if you are playing around with PHP codes with the help of an online PHP editor, to enjoy a full-fledged PHP environment (since online editors have several caveats, e.g. embedding PHP within HTML) up and running on your own machine is much better of an option to learn PHP. Please read our installing PHP on Windows and Linux if you are unfamiliar to PHP installation.
List of PHP Exercises :
- PHP Basic : 102 Exercises with Solution
- PHP Basic Algorithm: 136 Exercises with Solution
- PHP arrays : 59 Exercises with Solution
- PHP for loop : 38 Exercises with Solution
- PHP functions : 6 Exercises with Solution
- PHP classes : 7 Exercises with Solution
- PHP Regular Expression : 7 Exercises with Solution
- PHP Date : 28 Exercises with Solution
- PHP String : 26 Exercises with Solution
- PHP Math : 12 Exercises with Solution
- PHP JSON : 4 Exercises with Solution
- PHP Searching and Sorting Algorithm : 17 Exercises with Solution
- More to Come !
PHP Challenges :
- PHP Challenges: Part -1 [ 1- 25]
- More to come
Note : You may accomplish the same task (solution of the exercises) in various ways, therefore the ways described here are not the only ways to do stuff. Rather, it would be great, if this helps you anyway to choose your own methods.
Popularity of Programming Language Worldwide, May 2022 compared to a year ago:
Rank | Change | Language | Share | Trend |
---|---|---|---|---|
1 | Python | 27.85 % | -2.5 % | |
2 | Java | 17.86 % | -0.1 % | |
3 | Javascript | 9.17 % | +0.4 % | |
4 | C# | 7.62 % | +0.7% | |
5 | C/C++ | 7.0 % | +0.4 % | |
6 | PHP | 5.36 % | -1.0 % | |
7 | R | 4.34 % | +0.5 % | |
8 | ![]() |
TypeScript | 2.39 % | +0.7 % |
9 | ![]() |
Objective-C | 2.25 % | +0.0 % |
10 | Swift | 2.05 % | +0.3 % | |
11 | ![]() |
Matlab | `1.82% | +0.2 % |
12 | ![]() |
Kotlin | 1.58 % | -0.2 % |
13 | Go | 1.38 % | -0.1 % | |
14 | ![]() |
Rust | 1.15 % | +0.3 % |
15 | Ruby | 1.14 % | +0.0% | |
16 | ![]() |
VBA | 1.04 % | +0.0 % |
17 | ![]() |
Ada | 0.81 % | +0.2 % |
18 | ![]() |
Scala | 0.7 % | +0.2 % |
19 | ![]() |
Dart | 0.66 % | +0.0 % |
20 | Abap | 0.66 % | +0.1 % | |
21 | ![]() |
Visual Basic | 0.66 % | +0.0% |
22 | Lua | 0.5 % | +0.0 % | |
23 | ![]() |
Groovy | 0.45 % | +0.0 % |
24 | ![]() |
Perl | 0.45 % | +0.0 % |
25 | ![]() |
Julia | 0.4 % | +0.0 % |
26 | ![]() |
Cobol | 0.28 % | +0.0 % |
27 | Haskell | 0.28 % | +0.0 % | |
28 | Delphi/Pascal | 0.14 % | +0.0 % |
Source : https://pypl.github.io/PYPL.html
TIOBE Index for May 2022
May 2022 | May 2021 | Change | Programming Language | Ratings | Change |
---|---|---|---|---|---|
1 | 2 | ![]() |
Python | 12.74% | +0.86% |
2 | 1 | ![]() |
C | 15.59% | -1.80% |
3 | 3 | Java | 10.99% | -0.74% | |
4 | 4 | C++ | 8.83% | +1.01% | |
5 | 5 | C# | 6.39% | +1.98% | |
6 | 6 | Visual Basic | 5.86% | +1.85% | |
7 | 7 | JavaScript | 2.12% | -0.33% | |
8 | 8 | Assembly language | 1.92% | -0.51% | |
9 | 10 | ![]() |
SQL | 1.87% | +0.16% |
10 | 9 | ![]() |
PHP | 1.52% | -0.34% |
11 | 17 | ![]() |
Delphi/Object Pascal | 1.42% | +0.22% |
12 | 18 | ![]() |
Swift | 1.23% | -0.08% |
13 | 13 | ![]() |
R | 1.22% | -0.16% |
14 | 16 | ![]() |
Go | 1.11% | -0.11% |
15 | 12 | ![]() |
Classic Visual Basic | 1.03% | +0.38% |
16 | 21 | ![]() |
Objective-C | 1.03% | +0.24% |
17 | 19 | ![]() |
Perl | 0.99% | -0.05% |
18 | 37 | ![]() |
Lua | 0.98% | +0.64% |
19 | 11 | ![]() |
Ruby | 0.86% | -0.64% |
20 | 15 | ![]() |
MATLAB | 0.82% | -0.41% |
Source : https://www.tiobe.com/tiobe-index/
[ Want to contribute to PHP exercises? Send your code (attached with a .zip file) to us at w3resource[at]yahoo[dot]com. Please avoid copyrighted materials.]
List of Exercises with Solutions :
- HTML CSS Exercises, Practice, Solution
- JavaScript Exercises, Practice, Solution
- jQuery Exercises, Practice, Solution
- jQuery-UI Exercises, Practice, Solution
- CoffeeScript Exercises, Practice, Solution
- Twitter Bootstrap Exercises, Practice, Solution
- C Programming Exercises, Practice, Solution
- C# Sharp Programming Exercises, Practice, Solution
- PHP Exercises, Practice, Solution
- Python Exercises, Practice, Solution
- Java Exercises, Practice, Solution
- SQL Exercises, Practice, Solution
- MySQL Exercises, Practice, Solution
- PostgreSQL Exercises, Practice, Solution
- SQLite Exercises, Practice, Solution
- MongoDB Exercises, Practice, Solution
PHP: Tips of the Day
Concatenation Operators: You can use concatenation to join strings "end to end" while outputting them (with echo or print).
You can concatenate variables using a . (period/dot).
Example:
<?php // String variable $name = 'Jhon'; // Concatenate multiple strings (3 in this example) into one and echo it once done. echo '<p>Hello ' . $name . ', Nice to meet you.</p>'; // Concatenation Operators ?>
Output:
<p>Hello Jhon, Nice to meet you.</p>
Similar to concatenation, echo (when used without parentheses) can be used to combine strings and variables together (along with other arbitrary expressions) using a comma (,).
<?php $itemCount = 1; echo 'You have learn ', $itemCount, ' Tips', $itemCount === 1 ? '' : 's'; ?>
Output:
You have learn 1 Tips
String concatenation vs passing multiple arguments to echo
Passing multiple arguments to the echo command is more advantageous than string concatenation in some circumstances. The arguments are written to the output in the same order as they are passed in.
echo "The total is: ", $x + $y;
The problem with the concatenation is that the period . takes precedence in the expression. If concatenated, the above expression needs extra parentheses for the correct behavior. The precedence of the period affects ternary operators too.
echo "The total is: " . ($x + $y);
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework