PHP Tutorial: Learn from Basics
Updated on Nov 14, 2024 | 6 min read | 5.6k views
Share:
For working professionals
For fresh graduates
More
Updated on Nov 14, 2024 | 6 min read | 5.6k views
Share:
Table of Contents
PHP(PHP: HyperText Processor) is a free, open-source scripting language for the server-side, widely used in web development. It is also a general-purpose programming language developers can use for creating diverse applications.
PHP is a scripting language integrated with an HTML script and handles dynamic web pages, session tracking, databases, and other features.
Check out our free courses related to software development.
PHP is available at https://www.php.net/downloads in its most recent version.
Alternatively, you can get the PHP.msi package, which is the Windows installer, from sourceforge.net.
The first program practising program in every new programming language is printing ‘Hello World’. We shall see the code for the same below:
<html>
<body>
<h1>PHP page</h1>
<?php
echo “Hello World!”;
?>
</body>
</html>
A few facts about variables in PHP are mentioned below:
Learn Software Development Courses online from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs or Masters Programs to fast-track your career.
They are whole numbers without a decimal point, such as 5625. Integers can be both positive and negative. Integers may be allocated to variables or utilised in expressions.
Syntax:
$variable = 1234567;
$another_variable = -1234567 + 1234567;
A double value represents a decimal number. It can either be positive or negative.
Syntax:
$doub_var = 1.345679;
A boolean variable has two values, TRUE or FALSE.
A null data type may have only one value, i.e. NULL.
Syntax:
$variable_n = NULL;
A String data type represents a sequence or set of characters. Strings can either be written inside single or double quotes.
Syntax:
$string_s = “This is a String”;
A constant is a variable or an identifier that refers to a single, static value, which cannot change during script execution. Therefore, modifying or undefining a constant after it has been defined is impossible. Constant identifiers are usually written in uppercase as a matter of convention.
Syntax:
constant() // This function is used to return the value of a constant
Let us consider the expression a + b. In this expression, ‘a’ and ‘b’ are operands while ’+’ is the operator.
PHP supported operators are:
We shall only look into the first two types of operators for PHP basics- Arithmetic and Comparison operators.
Example: X = 200 , Y = 100
(+): This is the arithmetic addition operator; X + Y will produce 300 as a result.
(-): This is the arithmetic subtraction operator; X – Y will produce 100 as a result.
(*): This is the arithmetic product operator; X * Y will produce 20000 as a result.
(/): This is the arithmetic division operator; X / Y will produce two as a result.
(%): This is the arithmetic modulus operator, X % Y will produce 0 as a result.
(++): This is the arithmetic increment operator; X++ will produce 201 as a result.
(–): This is the arithmetic decrement operator; X– will produce 199 as a result.
Example: P = 10 , Q = 20
(==): This operator checks if the value of one operand is equal to the other or not and returns TRUE or FALSE; P == Q will produce FALSE as the output.
(!= ): This operator is just the opposite of the ‘==’ operator. It checks if the value of an operand is not equal to the other and returns TRUE or FALSE; P != Q will produce TRUE as the output.
(>): This operator checks if the value of the left-hand operator is greater than the right-hand operator or not; P > Q will return FALSE as the output.
(<): This operator checks if the value of the right-hand operator is greater than the left-hand operator or not; P < Q will return TRUE as the output.
(>=): This operator checks if the value of the left-hand operator is greater than or equal to the right-hand operator or not.(<=): This operator checks if the value of the right-hand operator is greater than or equal to the left-hand operator or not.
An array is a data structure that holds one or more items of a similar type in a single variable of the same name.
There are three types of arrays, with each array value accessible through an array index:
PHP’s widespread use is a natural outcome of its multiple benefits, making it a robust and productive scripting platform. A few advantages of PHP are mentioned below:
PHP is backed by vast reference material and a supportive community, making it an accessible and popular programming language for web development.
A Full-Stack Developer is probably the tech-related buzzword of the decade in software and web development. So, kick-start your Full-Stack Developer journey with upGrad’s Full-Stack Development Course.
Here’s what the course offers:
Visit upGrad to learn more!
Get Free Consultation
By submitting, I accept the T&C and
Privacy Policy
India’s #1 Tech University
Executive PG Certification in AI-Powered Full Stack Development
77%
seats filled
Top Resources