How to declare a variable in PHP

·

1 min read

To declare a variable in PHP we write the $ sign before the name of the variable :

for example, let's declare a variable named greeting and assign the string Hello to it.

$greeting="Hello"

we can echo out this variable like this: echo "$greeting World".

index.php:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <title>Demo</title>
</head>
<body>
<h1>
    <?php
    $greeting="Hello";
      echo "$greeting World";
    ?>
</h1>
</body>
</html>