What are the rules for naming a PHP variable?

0

The following two rules are needed to be followed while naming a PHP variable:

  • A variable must start with a dollar symbol, followed by the variable name. For example: $price=100; where price is a variable name.
  • Variable names must begin with a letter or underscore.
  • A variable name can consist of letters, numbers, or underscores. But you cannot use characters like +, –, %, & etc.
  • A PHP variable name cannot contain spaces.
  • PHP variables are case-sensitive. So $NAME and $name both are treated as different variables.
Php
asked May 17, 2023 at 17:08
Sign in to add a comment

0 Answers

0
📝 No answers yet!

Be the first to answer this interview question.

Your Answer

Sign in to post your answer and help the community.