w3resource

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 Challenges :

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, Jun 2020 compared to a year ago:

Rank Change Language Share Trend
1 Python 31.6 % +4.3 %
2 Java 17.67 % -2.4 %
3 Javascript 8.02 % -0.2 %
4 C# 6.87 % -0.4 %
5 PHP 6.02 % -0.9 %
6 C/C++ 5.69 % -0.2 %
7 R 3.86 % -0.1 %
8 Objective-C 2.5 % -0.3 %
9 Swift 2.24 % -0.1 %
10 up arrow TypeScript 1.86% +0.2 %
11 down arrow Matlab 1.72 % -0.2 %
12 up arrow Kotlin 1.54 % +0.2 %
13 up arrow Go 1.29 % +0.2 %
14 VBA 1.24 % -0.1 %
15 down arrow Ruby 1.23 % -0.1 %
16 Scala 1.0 % -0.1 %
17 Visual Basic 0.88 % -0.2 %
18 up arrow Rust 0.78 % +0.2 %
19 up arrow Dart 0.5 % +0.2 %
20 down arrow Perl 0.46 % -0.1 %
21 down arrow Abap 0.45 % -0.1 %
22   Lua 0.44 % +0.1 %
23   Ada 0.43 % +0.1 %
24 down arrow Groovy 0.41 % -0.1 %
25 up arrow Julia 0.39 % +0.1 %
26 down arrow Cobol 0.37 % +0.1 %
27 down arrow Haskell 0.28 % -0.0 %
28 down arrow Delphi 0.27 % +0.0 %

Source : http://pypl.github.io/PYPL.html

TIOBE Index for June 2020

Jun 2020 Jun 2019 Change Programming Language Ratings Change
1 2 up arrow C 17.19% +3.89%
2 1 down arrow Java 16.10% +1.10%
3 3 Python 8.36% -0.16%
4 4 C++ 5.95% -1.43%
5 6 up arrow C# 4.73% +0.24%
6 5 down arrow Visual Basic 4.69% +0.07%
7 7 JavaScript 2.27% -0.44%
8 8 PHP 2.26% -0.30%
9 22 up arrow R 2.19% +1.27%
10 9 down arrow SQL 1.73% -0.50%
11 11 Swift 1.46% +0.04%
12 15 up arrow Go 1.02% -0.24%
13 13 Ruby 0.98% -0.41%
14 10 down arrow Assembly language 0.97% -0.51%
15 18 up arrow MATLAB 0.90% -0.18%
16 16 Perl 0.82% -0.36%
17 20 up arrow PL/SQL 0.74% -0.19%
18 26 up arrow Scratch 0.73% +0.20%
19 19 Classic Visual Basic 0.65% -0.42%
20 38 up arrow Rust 0.64% +0.38%

Source : https://www.tiobe.com/tiobe-index/

List of Exercises with Solutions :

[ 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 :



PHP: Tips of the Day

To use the constant simply use its name:

Example:

if (EARTH_IS_FLAT) {
 print "Earth is flat";
}
print APP_ENV_UPPERCASE; 

Output:


or if you don't know the name of the constant in advance, use the constant function:

// this code is equivalent to the above code
$const1 = "EARTH_IS_FLAT";
$const2 = "APP_ENV_UPPERCASE";
if (constant($const1)) {
 print "Earth is flat";
}
print constant($const2);

Output: