PHP Variable

  • Hi guys, Today we built-in php variables tutorial, variable is a most important part of php project.
  • PHP is a Loosely Typed Language, we don't need to disclose the data types of variables. It automatically analyzes the values and converts them to the correct datatype.

Rules for PHP variables:

  • PHP variable name starts with the `$` icon
  • PHP variable name cannot start with a number
  • PHP variable name must start with a alpha-numeric characters or the underscore character like (A-z, 0-9, and _ )
  • PHP variable names are case-sensitive like `$count` and `$COUNT` this is a two different variables

PHP Syntax

<?php
	$a = 123; //a is variable
?>

PHP Example

Edit it yourself

<!DOCTYPE html>
<html>
<body>

<?php
  $c = 89;
  $php = 99;
  $java = 75;

  $sum = $c + $php + $java;
  $per = $sum/3;

  echo "my percentage is a ".$per;
?>


</body>
</html>

Output of PHP variable

Edit it yourself

my percentage is a 87.666666