Declaring variables is part of the routine of any programmer. In PHP, the statement occurs in a very simple way, as you can see in the example below:

<?php
$a = 1;
?>

In the example, we declare the variable “a” taking the integer value 1.

 

Unlike some languages, the declaration of variables in PHP uses the “$” character and there is no need to declare the variable type (integer, decimal, string etc). So, over the processing of information, a variable can take several forms:

<?php
$a = 1;// integer
$a = “Test”; // string
$a = 1,0; // decimal
$a = NULL;// null
?>

By default, every PHP variable is declared in the local scope, so it can only be used by set elements and includes in the block used. If there is a need for one variable to be used globally, in other calls, that one must be declared as follows:

<?php
global $a;
?>

You can still use what we call static variables. This type of variable does not lose its value  in every method call in the local scope and it is capable of storing information.

Static variables are widely used in recursive functions, check below for an example:

<?php
function Test()
{
$a = 0;
echo $a;
$a++;
}
?>

 

 

 

In the above function, in each call the variable will be reset and incremented at the end, but in each new call function the value will be reset again and so the logic loses its function. In that case you must use a static variable that will store a new value to each call and so the self-increment will work properly.

<?php
function Test()
{
static $a = 0;
echo $a;
$a++;
}
?>

By understanding the variable declaration of resources it is possible to optimize the application performance and thus make them more effective in their processes.

GLOBAL VARIABLES IN SCRIPTCASE

Within Scriptcase you can register on the administrative panel some global variables that can be used in any application built on the tool, all in a simple and uncomplicated WAY, the main characteristic of our tool.

In addition, you can also access some global variables that are already available in a standard way in our tool, as you can see in the example below:

[var_login] = {login};

You might also like…

PROCESAMIENTO AJAX EN SCRIPTCASE

Ajax en los formularios de Scriptcase puede usarse para recargar un campo de tipo de select basado e...

IMPORTAR IMAGENES DE LA BASE DE DATOS Y UTILIZAR CLASES DE BOOSTRAP

Como muchas personas ya saben, Bootstrap es una biblioteca de front-end libre y de código abierto p...

TENDENCIAS DE DESARROLLO WEB PARA 2017

Usted verá en este post tendencias para 2017 en Diseño Web, en el medio digital y en el desarrollo...

Comment this post

Get new posts, resources, offers and more each week.

We will use the information you provide to update you about our Newsletter and Special Offers. You can unsubscribe any time you want by clinck in a link in the footer of any email you receive from us, or by contacting us at sales@scriptcase.net. Learn more about our Privacy Police.