Basics of PHP language

0

On this post we will learn about the basics of PHP language. The is one of the most important part where we will get the idea about how we should design our coding for a better performance. So let’s start from here.

The most basic parts of a programming are:

  1. Variable
  2. String
  3. Operator
  4. Condition
  5. Loop
  6. Array
  7. Function
  8. Class
  9. Super global variable.

Let’s talk about the topics we mentioned here. These are the most basic things of this language.

Variable: every programming language has this basic feature, where we will declare a variable to contain a particular value or a string. In other high level languages it is practiced that the variable type needs to be mentioned. If the variable is a integer or a float number, if the number is a string or a character. But in PHP it is not required to mention this. We can simply declare a variable by putting dollar sign “$” in front of any word or character. The variable looks like below:

$a = 5;

$b = “hello”;

$hello= “world”;

String: first of all we need to know what string means. A string is a group of alpha numeric characters set. This string is included white space and long gaps. This language has a special ability to process string directly as a variable. Also a string can be divided by different delimiters and break them into an array. The example of a string is given below:

$sting= “this is a string.”;

Operator: operators are the symbols which mean that there is something needs to be done between two variables. The operators are four types and these are Bitwise operator, comparison operator, logical operator and incremental or detrimental operator. In here we will mention very few operators of each type. But in future we will see these operators on some meaningful scripts.

Bitwise operators: &(and), | (or), ^(Xor), ~(not)

Comparison operator: ==(equal), ===(identical), > (greater than), < (less than), != (not equal)

Logical operator: and, or, Xor, ! (not)

Incremental or detrimental operator:  ++ (incremental), — (detrimental)

 

Condition: we all know what condition means. Now what condition means in programming language is if there are two variables and there is a conditional operator between them and the statement will be true only if the condition match. Now we can match more than one condition. Also we can create nested conditions. Let’s see what the basic kind of conditional statement we have is in programming language.

Simple conditional statement: if else condition

Nested conditional statement: if elseif else condition

Loop: in programming one of the very important and really necessary parts is to create a loop until the condition or conditions matches. For that we need to learn how to use these loops and where we should use which one. Let’s know about the basic kind of loops first.

There are four loops in PHP language, these are for loop, foreach loop, while loop, do while loop.

We will talk more about these loops in future.

 

Array:  this is also a kind of variable. But the fact of this variable kind is it can contain more than one variable at once. Also we can make it a set of variables in one variable this is a very useful type of variable for a big data structure. We just need to understand the location of variables within a variable.     Let’s learn how we see a array in PHP language:

$a[]=array( “a”, “b”, “foo”, “bar”);

This above array is an array of four members.

 Function: function is a set of codes which is created for some specific reasons. If we try to be clear about function then we should define it as, there are a set of work usually done by one simply calling a function, where the function will be defined with all the processes are going to be done. In below a example is provided.

Function function_name(){

The processes will be defined in here.

}

 

Class:  we all know PHP is an Object oriented scripting language. So class is the main reason to call it object oriented. There every class is an object and we can call this object on different programs for doing different kind of work. Every class contains function or functions. We can also call different functions from the class. But there we will see how to create a class and how to call a class.

In below we will see how to create a class.

class test {

define variables;

define functions;

}

Now we will see how to call a class into a variable.

$test= new test;

 

Super global variable: there are few super global variables which can be accessed from any function, files or classes. So this does not have any restrictions to put. This is the main reason to call these variables as super global variables. Below we will mention the variables.

  1. $GLOBALS
  2. $_SERVER
  3. $_REQUEST
  4. $_POST
  5. $_GET
  6. $_FILES
  7. $_ENV
  8. $_COOKIE
  9. $_SESSION

So here we finish our basic part. From next article we will discuss about the beginning of the php programming and so on.

 

Leave A Reply

Your email address will not be published.