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.
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
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.
In php,Output is displayed on the browser using echo as follows:
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:
A string is a sequence of characters that holds letters and numbers. It can be anything written inside single or double quotes.
An integer is a non-decimal number typically ranging between -2,147,483,648 and 2,147,483,647.
A float is a number with a decimal point. It can be an exponential number or a fraction.
A Boolean represents two values: True or False.
Array is a collection of similar data elements stored in a single variable.
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.
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:
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:
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.
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: