Document

PHP Overview

PHP is a server-side scripting language, which is used to manage dynamic web pages, databases and build websites with features like session tracking and e-commerce. On a day of 1995, Rasmus Lerdorf unleashed the first version of “Hypertext Preprocessor” also known as the PHP language. It is also integrated with several popular databases like MySQL, PostgreSQL, Microsoft SQL Server, Oracle etc.

Uses of PHP

PHP can perform several system functions like opening files, CRUD operations on data stores, general-purpose scripting, etc. Besides system operations, there are also other uses like

Basic Syntax PHP

A PHP script can be written anywhere inside the HTML document. A PHP script starts with <?php tag and ends with ?>. We can write our logic inside this tag and it will be executed accordingly.

Displaying output in php

In php,Output is displayed on the browser using echo as follows:

Data Types in PHP

PHP DataTypes

Data type specifies the type of value a variable requires to do various operations without causing an error. By default, PHP provides the following built-in data types:

  1. String
  2. A string is a sequence of characters that holds letters and numbers. It can be anything written inside single or double quotes.

  3. Integer
  4. An integer is a non-decimal number typically ranging between -2,147,483,648 and 2,147,483,647.

  5. Float
  6. A float is a number with a decimal point. It can be an exponential number or a fraction.

  7. Boolean
  8. A Boolean represents two values: True or False.

  9. Array
  10. Array is a collection of similar data elements stored in a single variable.

  11. NULL
  12. Null is a special data type with only one value which is NULL. In PHP, if a variable is created without passing a value, it will automatically assign itself a value of NULL.

PHP Conditional & Iterative Statements


PHP Conditional Statements

Conditional Statements are used to perform actions based on different conditions. Sometimes when we write a program, we want to perform some different actions for different actions. We can solve this by using conditional statements.
In PHP we have these conditional statements:

  1. if Statement.
  2. if-else Statement
  3. If-elseif-else Statement
  4. Switch statement

PHP Iterative Statements

terative statements are used to run same block of code over and over again for a certain number of times.
In PHP, we have the following loops:

  1. while Loop
  2. do-while Loop
  3. for Loop
  4. foreach loop

Function in PHP

Function arguments are variables of some supported data type that are processed within the body of the function. It can take input as an argument and return value.
PHP has more than 1000 built-in functions, and in addition, you can also create your own functions.

Advantages:

User Defined Functions:

Apart from built-in functions, We can also create our own functions and call them easily. A user-defined function looks something like this:

Note: A function name should only start with letters and underscore only. It can’t start with numbers and special symbols.
Example:

PHP OOPS consistes of:

Types of Superglobal variables

Document
PROCODING
Copyright © 2023 to Rohit Negi