Changes

Jump to: navigation, search

An Introduction to PHP Variables

653 bytes added, 17:04, 25 May 2007
Changing the Type of a PHP Variable
As we mentioned at the beginning of this chapter PHP supports a number of different variable types (specifically integer, float, boolean, array, object, resource and string). We will look at these types in detail later in this chapter. First we are going to look at changing the type of a variable after it has been created.
PHP is what is termed a ''loosely typed'' language.This contrasts with programming languages such as Java which are ''strongly typed'' languages. The rules of a strongly typed language dictate that once a variable has been declared as a particular type, its type cannot later be changed. Loosely typed languages such as PHP (and JavaScript) allow the variable type to be changed at any point simply by assigning a value of different to to it. For example we can create a variable and assign it an integer and later change it to a string type by assigning a string to it: <pre><?php $myNumber = 6; // variable is of integer type $myNumber = six; // variable has now changed to string type ?></pre?

Navigation menu