Blog_Banner_Asset
    Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconFull Stack Developmentbreadcumb forward arrow iconphp Tutorial: Learn from Basics

php Tutorial: Learn from Basics

Last updated:
21st Sep, 2022
Views
Read Time
6 Mins
share image icon
In this article
Chevron in toc
View All
php Tutorial: Learn from Basics

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.

Explore Our Software Development Free Courses

Ads of upGrad blog

Installing PHP on your Computer

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

Writing your First Program in PHP

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>

Variable and Data Types in PHP

A few facts about variables in PHP are mentioned below:

  • In PHP, all variables are marked with a dollar symbol ($) at the beginning of their declaration.
  • The ‘=’ operator is used to assign variables to expressions.
  • Variables in PHP do not have inherent or intrinsic data types. A variable cannot know its usage to hold an integer or a string until its utilisation.

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.

Explore our Popular Software Engineering Courses

Data Types in PHP

Integer

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;

Double

A double value represents a decimal number. It can either be positive or negative.

Syntax:

$doub_var = 1.345679;

Boolean

A boolean variable has two values, TRUE or FALSE.

NULL

A null data type may have only one value, i.e. NULL.

Syntax:

$variable_n = NULL;

String

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”;

In-Demand Software Development Skills

Constants in PHP

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

Operators in PHP

Let us consider the expression a + b. In this expression, ‘a’ and ‘b’ are operands while ’+’ is the operator. 

PHP supported operators are:

  • Arithmetic Operators
  • Operators for Comparison
  • Relational Operators
  • Assignment or Short-Hand Operators
  • Conditional Operators

We shall only look into the first two types of operators for PHP basics- Arithmetic and Comparison operators.

Arithmetic 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.

Comparison Operators

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.

Arrays in PHP

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:

  • An array with a numeric index is called a numeric array. It is a contiguous memory allocation where users store and retrieve values using their indexes.
  • An array with strings as indexes is known as an associative array. Instead of storing element values in contiguous index order, this method saves element values in conjunction with key values.
  • A multidimensional array contains a single or more than one array and values accessible by using various indices in different directions.

Read our Popular Articles related to Software Development

Advantages of using PHP

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:

  • Accelerated loading speed: PHP enables websites to load quicker than many other web development tools. On the other hand, reduced loading time is a critical SEO Ranking Feature that helps promote a website. 
  • Open-source software, mostly free of charge: PHP is a free-to-use technology that enables significant cost reductions in the development process. Additionally, the bulk of development tools often used in conjunction with PHP is open-source and freely available.
  • Can be Integrated with HTML:  The extraordinary compatibility between PHP and HTML is due to PHP’s ability to include HTML programming into its code. PHP can be added into the HTML Script with the use of <?php ?> tags.
  • Compatible with Cloud technologies: Cloud computing technologies, such as Amazon Web Services, are used by contemporary goods for various functions. Several cloud services, including AWS Lambda, can handle applications based on PHP.

Conclusion

PHP is backed by vast reference material and a supportive community, making it an accessible and popular programming language for web development. 

upGrad’s Executive Post Graduate Program in Full Stack Development

Ads of upGrad blog

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:

  • The status of an Alumni from IIIT Bangalore
  • More than 7 case studies and projects to choose from
  • upGrad 360° Support for Your Career
  • Career Change Bootcamp for non-technical and new programmers in the software industry
  • Access to Faculty and Industry Leaders from across the world
  • Query assistance is accessible around the clock, seven days a week

Visit upGrad to learn more!

Profile

Pavan Vadapalli

Blog Author
Director of Engineering @ upGrad. Motivated to leverage technology to solve problems. Seasoned leader for startups and fast moving orgs. Working on solving problems of scale and long term technology strategy.

Frequently Asked Questions (FAQs)

1What is the full form of PHP?

Hypertext Processor or Pre hypertext processor is the full form of PHP.

2How much time does it take for a beginner to learn PHP?

PHP may take anywhere from three to six months to learn, depending on how much time and effort you put into the process. PHP's friendly syntax makes it an excellent place for those new to the language to begin their studies.

3What is the eligibility criterion for upGrad’s Full-Stack Developer Course?

A candidate applying for the program should have passed their Bachelor’s Degree with a 50% minimum to be eligible.