PHP : The Basics

Written on October 26, 2016

What is PHP?

php stands for Hypertext Preprocessor. We have posted a lot about the python web development framework Django. It is somewhat similar to Django. PHP is the most widely used language for the server. It is used for handling the server. It is also used to interact with your database so that you can save the data for future use. PHP is also open source and free to use. PHP is very easy to learn that is why many developers believe that every new developer ;learn this as the first language.


Installation of PHP is very simple and can be done easily. Just go to this link(


You have to insert starting and ending PHP tags in the html where ever you want to run some PHP script. Whenever you want to run some php code save the file with the .php extension. For eg:- save this file as new.php and run using the server.




Variables are the most important thing that any language must have. Variables in PHP are assigned without specifying the type of the variable.

This will assign $x as the value of 10. For printing you can use both echo or print. Both of them have very small difference. echo function does not return anything while print does return 1. For this reason echo is faster than print.

echo $name;

This will print out the ‘Ranvir Singh’ on the browser.

String handling funtions 

String data type has many build in functions which can be used to make our work easier. For studying such functions see this post.


Constants are the variables whoes values never change during the execution of the program. Similarly PHP constants are used for similar purposes. define keyword is used to declare a constant.


define(“variable_name”, “Value_of_the_variable”, “case-insensitive( true/false)”);

case-insensitive is used if you want to make it case insensitive.

Conditional statements

  • if

  • if-else

  • if-elif

  • nested if

  • switch statements

These statements are all similar to the statements in any other language.


  • while

  • do while

  • for

  • for each

All other loops are similar but foreach is somewhat different.

'; } ?>


Functions are also similar to other languages.


function functioname(){ //.... Somestuff return some_variable; } echo functionname();


There are three types of arrays in PHP.

  • Indexed Array : Accessed using the numbers

  • Associative Array : Elements are accessed using the programmer given values

  • Multi-dimensional Array : Similar to matrices.

echo count($arrayname);

This function will print the total number of elements in an array. That’s it for now. With the provided knowledge you can easily build anything that you want. Think of something that you want to build. If you get any problem ask below.