Variables
All variables in PHP start with a dollar sign ($). Unlike many other languages, PHP does not have different types of variable for integers, floating-point numbers, arrays, or Booleans. They all start with a $, and all are interchangeable. As a result, PHP is a weakly typed language, which means you do not declare a variable as containing a specific type of data; you just use it however you want to.
Save the code in Listing 39.1 into a new file called ubuntu1.php.
Listing 39.1. Testing Types in PHP
<?php $i = 10; $j = "10"; $k = "Hello, world"; echo $i + $j; echo $i + $k;?>
To run that script, bring up a console and browse to where you saved it. Then type this command:
matthew@seymour:~$ php ubuntu1.php
If PHP is installed correctly, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access