Variables in PHP

ad, authenticate, script, geeks corner, json, image, picture, server, file, write, read, close, fread, readfile, fclose, walden, systems, walden systems, php, functions, variable arguments , variable, data types, array, string, integer, float resource, object
PHP is a popular general-purpose scripting language that is especially suited to web development. Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world.

Variables are used to store data, like string of text, numbers, etc. Variable values can change over the course of a script. In PHP, just like Python, a variable does not need to be declared before adding a value to it. PHP automatically converts the variable to the correct data type, depending on its value. After declaring a variable it can be reused throughout the code. The assignment operator, =, is used to assign value to a variable.

Below are some examples of assigning variables :

Integer assignment
$x = 12

Floating point assignment
$y = 1.0

String assignment
$name = "John Doe"

Ordered list assignment
$list = ( "abc", "def' , "ghi" )
$list2 = ( "elem1"=>"abc", elem2=>"def' , elem3=>"ghi" )


PHP data types

PHP has a total of eight data types which we use to construct our variables. The first five are simple types, and the next two, arrays and objects, are compound types. Compound types can package up other arbitrary values of arbitrary type, whereas the simple types cannot.

Integers − Whole numbers, without a decimal point, like 12345.

Doubles − Floating-point numbers, like 3.14159 or 1.1.

Booleans − Have only two possible values either true or false.

NULL − A special type that only has one value, NULL.

Strings − Sequences of characters, like 'John'.

Arrays − Named and indexed collections of other values.

Objects − Instances of classes, which can package up both other kinds of values and functions that are specific to the class.

Resources − Special variables that hold references to resources external to PHP such as database connections.