190 likes | 653 Views
PHP - Variables. Variable name: starts with a letter or _, followed by letters, _s, or digits PHP is a loosely typed language no declaration of variables (like Perl) Variable names are case sensitive. PHP - Variables. $a = 3; $b = 1.43; $c = 1.3 e4; $d = 7E-10; $first1 = “Mike”; // ok
E N D
PHP - Variables • Variable name: starts with a letter or _, followed by letters, _s, or digits • PHP is a loosely typed language • no declaration of variables (like Perl) • Variable names are case sensitive
PHP - Variables • $a = 3; • $b = 1.43; • $c = 1.3 e4; • $d = 7E-10; • $first1 = “Mike”; // ok • $first2 = ‘Sarah’; // ok • $first3 = Jane; // ok
PHP – Printing variables • $a = “Mike”; • Using double quotes; variables expand • echo “hello $a”; // hello Mike • Using single quotes, variables do not expand • echo ‘hello $a’; // hello $a
PHP – Printing variables • We can also use the print function • print “Using print: Hello $a”; • print( “Using print( ): Hello $a” ); • print( “Printing using several<br> Lines” );
PHP – Variable scope • A variable is in scope until the end of the PHP script