PHP variables - dynamically typed. What does that mean?
Archive - Originally posted on "The Horse's Mouth" - 2012-11-08 12:50:32 - Graham Ellis
When writing in many languages, the programmer specifies the name of each variable he'll be using, and the type of data it's going to contain. Computers work with patterns or 0s and 1s (binary), and a group of 32 of these could contain a whole number (also known as an integer), a real number (a float), a string of 4 characters (ASCII text) or various other things. That's why the type is declared - so that the correct interprettation is put onto the bit pattern later on n the program. Languages like C and C++ work in this way - the code runs very fast, but it can be quite slow to actually write it. [C Courses].
As well as it being a lot of extra work to declare all your variables, and their types, ahead of time, you need to know how much memory you'll need as you write your program. If I'm going to allocate up to 10 float values for the ages of pets (if we're writing some sort of vetinary application), then that puts a limit on the program and we have a problem when the woman with 27 cats.
The solution applied in PHP (and Perl, Python, Ruby and Lua of the languages we teach) is to use dynamic variable allocation and typing

In PHP, variables can contain whole numbers (integers), numbers with decimals (floats), strings of text, and arrays ... and a whole load of other things too like objects, bool (boolean) and resources - such as file handles.
Explanation from one of our PHP courses running this week. Opening image - our cat Charlie, who really does not want to be one of 27!