Explore Courses
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Birla Institute of Management Technology Birla Institute of Management Technology Post Graduate Diploma in Management (BIMTECH)
  • 24 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Popular
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science & AI (Executive)
  • 12 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
University of MarylandIIIT BangalorePost Graduate Certificate in Data Science & AI (Executive)
  • 8-8.5 Months
upGradupGradData Science Bootcamp with AI
  • 6 months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
OP Jindal Global UniversityOP Jindal Global UniversityMaster of Design in User Experience Design
  • 12 Months
Popular
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Rushford, GenevaRushford Business SchoolDBA Doctorate in Technology (Computer Science)
  • 36 Months
IIIT BangaloreIIIT BangaloreCloud Computing and DevOps Program (Executive)
  • 8 Months
New
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Popular
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
Golden Gate University Golden Gate University Doctor of Business Administration in Digital Leadership
  • 36 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
Popular
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
Bestseller
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
IIIT BangaloreIIIT BangalorePost Graduate Certificate in Machine Learning & Deep Learning (Executive)
  • 8 Months
Bestseller
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in AI and Emerging Technologies (Blended Learning Program)
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
ESGCI, ParisESGCI, ParisDoctorate of Business Administration (DBA) from ESGCI, Paris
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration From Golden Gate University, San Francisco
  • 36 Months
Rushford Business SchoolRushford Business SchoolDoctor of Business Administration from Rushford Business School, Switzerland)
  • 36 Months
Edgewood CollegeEdgewood CollegeDoctorate of Business Administration from Edgewood College
  • 24 Months
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with Concentration in Generative AI
  • 36 Months
Golden Gate University Golden Gate University DBA in Digital Leadership from Golden Gate University, San Francisco
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Deakin Business School and Institute of Management Technology, GhaziabadDeakin Business School and IMT, GhaziabadMBA (Master of Business Administration)
  • 12 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science (Executive)
  • 12 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityO.P.Jindal Global University
  • 12 Months
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (AI/ML)
  • 36 Months
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDBA Specialisation in AI & ML
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
New
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGrad KnowledgeHutupGrad KnowledgeHutAzure Administrator Certification (AZ-104)
  • 24 Hours
KnowledgeHut upGradKnowledgeHut upGradAWS Cloud Practioner Essentials Certification
  • 1 Week
KnowledgeHut upGradKnowledgeHut upGradAzure Data Engineering Training (DP-203)
  • 1 Week
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
Loyola Institute of Business Administration (LIBA)Loyola Institute of Business Administration (LIBA)Executive PG Programme in Human Resource Management
  • 11 Months
Popular
Goa Institute of ManagementGoa Institute of ManagementExecutive PG Program in Healthcare Management
  • 11 Months
IMT GhaziabadIMT GhaziabadAdvanced General Management Program
  • 11 Months
Golden Gate UniversityGolden Gate UniversityProfessional Certificate in Global Business Management
  • 6-8 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
IU, GermanyIU, GermanyMaster of Business Administration (90 ECTS)
  • 18 Months
Bestseller
IU, GermanyIU, GermanyMaster in International Management (120 ECTS)
  • 24 Months
Popular
IU, GermanyIU, GermanyB.Sc. Computer Science (180 ECTS)
  • 36 Months
Clark UniversityClark UniversityMaster of Business Administration
  • 23 Months
New
Golden Gate UniversityGolden Gate UniversityMaster of Business Administration
  • 20 Months
Clark University, USClark University, USMS in Project Management
  • 20 Months
New
Edgewood CollegeEdgewood CollegeMaster of Business Administration
  • 23 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
KnowledgeHut upGradKnowledgeHut upGradBackend Development Bootcamp
  • Self-Paced
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 5 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
upGradupGradDigital Marketing Accelerator Program
  • 05 Months

PHP Tutorial: Learn from Basics

Updated on 14 November, 2024

5.4K+ views
6 min read

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.

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.

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

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.

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

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!

Frequently Asked Questions (FAQs)

1. What is the full form of PHP?

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

2. How 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.

3. What 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.

RELATED PROGRAMS