Difference between Single quotes ‘ and Double quotes ” in PHP

In this tutorial we will learn about the difference in single quotes and double quotes. Theoretically if we understand then single quotes doesn’t parse the data and double quotes is said to be interpreted.

In simple words if we understand then if we write anything in double quotes then it passes the value in the variable whereas if we write anything inside single quotes then it passes the value as string. We will see it though example to make it clear.

Output:

It shows that if we write within the single quotes it doesn’t parse the data and shows the value as string.

  • One more thing we should know that we cannot use Single quotes within single quotes and Double quotes within double quotes.

This is a wrong way of using quotes and we will fetch an error if it is compiled instead of this we can use the below format:

  • To use double quotes within double quotes and single quotes within single quotes then we have to use skip “\”.

Reference:

Tagged :

What is var_dump in PHP

Var_dump function is used to check the data type of a variable. In PHP we do not have to write the data type while declaring the variable so if we want to print the data type we will use “var_dump” function to see type of data of the variable.

For example:

Output:-

Here, we can see in the output that it has printed the data type of all the variables which we have used.

Reference:

Tagged : / /

PHP Global and Local Variable

In this tutorial we will learn about declaring global and local variable in PHP.

Initially we will see what is local variable and global variable with examples.

Here if we see the variable is declared inside the function “local” so it will work inside the local function only until we return the value inside the function.

In this we can see that the variable “a” is declared outside the function local, so it won’t work inside the function until we call it.

If we see the output for this we will see an error since “a” is a local variable and it will not work beyond the function “test”.

Now in this code if we see, variable “a” is declared globally and we will get an error if we call it inside any function.

To execute the global variable in the function we need to use predefined variable “global” inside the function.

We will see now that it will return value inside the function as well as outside the function.

References:

Tagged : / / /