solutionbrazerzkidai.blogg.se

Basic data types and operations
Basic data types and operations











  1. BASIC DATA TYPES AND OPERATIONS HOW TO
  2. BASIC DATA TYPES AND OPERATIONS 64 BIT
  3. BASIC DATA TYPES AND OPERATIONS 32 BIT
  4. BASIC DATA TYPES AND OPERATIONS CODE

returns true if the values are not equalĬompares values of x and y. Since 1 is integer and “1” is stringĬompares values of x and y.

basic data types and operations

They can also be used together with arithmetic operators.Ĭomparison operators are used to compare values and data types.Ĭompares x and y then returns true if they are equalįalse or 0. PHP supports the following operators.Īssignment operators are used to assign values to variables. The concatenate operator works on strings values too. PHP Operators Arithmetic operatorsĪrithmetic operators are used to perform arithmetic operations on numeric data.

BASIC DATA TYPES AND OPERATIONS CODE

define(‘PI’,3.14) //creates a constant with a value of 3.14 Once you define PI as 3.14, writing a code like below will generate an error PI = 4 //PI has been defined as a constant therefore assigning a value is not permissible. Let’s now look at an example that defines a constant. Suppose we are developing a program that uses the value of PI 3.14, we can use a constant to store its value. Output: int(1) float(1.5) string(10) "I Love PHP" bool(true) PHP Constantĭefine constant– A constant is a variable whose value cannot be changed at runtime.

BASIC DATA TYPES AND OPERATIONS HOW TO

The code below demonstrates how to use the var_dump function. Ībove Code Output 2 The var_dump function is used to determine the data type. The code below demonstrates explicit type casting. PHP also allows you to cast the data type. The diagram below shows PHP implementing the above example. In other languages such as C#, you have to cast the variables. Type casting in PHP is done by the interpreter. This is very useful when performing arithmetic computations that require variables to be of the same data type. Type casting is converting a variable or value into a desired data type. Performing arithmetic computations using variables in a language such as C# requires the variables to be of the same data type.

basic data types and operations

The same algorithm can be used for different input data values.įor example, suppose that you are developing a calculator program that adds up two numbers, you can create two variables that accept the numbers then you use the variables names in the expression that does the addition. Variables help separate data from the program algorithms. Output: Hypertext Pre Processor Use of Variables Let’s now look at how PHP determines the data type depending on the attributes of the supplied data. You cant use characters such as the dollar or minus sign to separate variable names. You can instead use an underscore in place of the space e.g. Variable names must not contain any spaces, “$first name” is not a legal variable name. Variable names are case sensitive this means $my_var is different from $MY_VARĪll variables names must start with a letter follow other characters e.g. Let’s now look at the rules followed when creating variables in PHP.Īll variable names must start with the dollar sign e.g. Just like in other programming languages, PHP supports variables too. Variables are used to store data and provide stored data when needed. You can add water into the glass, drink all of it, refill it again etc. Think of a variable as a glass containing water. The scope of a variable determines its visibility.Ī Php global variable is accessible to all the scripts in an application.Ī local variable is only accessible to the script that it was defined in.

basic data types and operations

PHP VariableĪ variable is a name given to a memory location that stores data at runtime. Floating point numbers are larger than integers.īefore we go into more details discussing PHP data types, let’s first discuss variables. The maximum value of a float is platform-dependent.

basic data types and operations

they are also known as double or real numbers. The constant PHP_INT_MAX is used to determine the maximum value.įloating point number – decimal numbers e.g.

BASIC DATA TYPES AND OPERATIONS 64 BIT

64 bit machines usually have larger values.

BASIC DATA TYPES AND OPERATIONS 32 BIT

On a 32 bit machine, it’s usually around 2 billion. The maximum value of an integer is platform-dependent. PHP implicitly supports the following data types PHP determines the data types by analyzing the attributes of data supplied. PHP is a loosely typed language it does not have explicit defined data types. True or false values are classified as Boolean. Numbers with decimal points are classified as floating points. A Data type is the classification of data into a category according to its attributes Īlphanumeric characters are classified as strings













Basic data types and operations