What are variables in PHP and how to define them?

Variables are "containers" for storing information.

Purposes of variable in PHP:

  • A variable name must start with a leading dollar sign ($),which is followed by name.
  • A variable name cannot start with a number.
  • Variable names are case-sensitive ($age and $AGE are two different variables)
  • Variables used before they are assigned have default values.
  • PHP does a good job of automatically converting types from one to another when necessary.

Example:

<html>

<body>

<?php

$txt = "Hello,how’s life goin on?";

echo "Gud $txt";

?>

</body>

</html>

 

Output:

Gud, Hello,how’s life goin on?

PHP