PHP Variables and Data Types
Variable Declaration
<?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>
Data Types
<?php
$str = "String"; // String
$int = 42; // Integer
$float = 3.14; // Float
$bool = true; // Boolean
$arr = array(1, 2, 3);// Array
$obj = new MyClass(); // Object
$null = NULL; // NULL
?>
Variable Scope
<?php
$globalVar = "I'm global";
function test() {
$localVar = "I'm local";
global $globalVar; // Access global variable
echo $globalVar;
}
?>
Back to Tutorials