1
I wonder if a variable in php
can begin with underline
, for example: $_1teste;
1
I wonder if a variable in php
can begin with underline
, for example: $_1teste;
3
Yes. Yes, you can!
According to the official PHP documentation about variables:
"A valid variable name starts with a letter or underline"
Examples:
$4site = 'not yet'; // inválido; começa com um número
$_4site = 'not yet'; // válido; começa com um sublinhado
$täyte = 'mansikka'; // válido; 'ä' é um caracter ASCII (extendido) 228
1
Yes, the variables can start with a letter or underline.
For example:
// Variaveis validas;
$_variavel = 'valor';
$_2variavel = 'valor';
$_1234_vel = 'valor';
// Variaveis não validas;
$+variavel = 'valor';
$-2variavel = 'valor';
$?1234_vel = 'valor';
See you around!
1
Yes, in php these are the rules.
Consult official PHP documentation about variables:
"A valid variable name starts with a letter or underline"
Examples:
// Variaveis validas;
$_variavel = 'valor';
$_2variavel = 'valor';
$_1234_vel = 'valor';
// Variaveis não validas;
$+variavel = 'valor';
$-2variavel = 'valor';
$?1234_vel = 'valor';
Browser other questions tagged php
You are not signed in. Login or sign up in order to post.
PHP Manual>Language Reference>Variables
– Guilherme Lautert
It is not mandatory but can!
– rray
http://php.net/manual/en/language.variables.basics.php
– Reginaldo Rigo
That kind of question I would close, like "sloth".
– Guilherme Lautert