number as variable name not possible right? But this works
${4} = 444;
echo ${4};
Question: How much is this justified using this syntax? and where is info about this in documentation? I not found.
Rules for PHP variables: 1 A variable starts with the $ sign, followed by the name of the variable 2 A variable name must start with a letter or the underscore character 3 A variable name cannot start with a number 4 A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) More items...
A variable name shouldn’t contain any symbol except underscore. It may be a combination of alphabets and numbers but numbers must not be placed at the starting point. In PHP, a variable name cannot contain spaces.
PHP has the following predefined constants for integers: PHP has the following functions to check if the type of a variable is integer: Check if the type of a variable is integer: A float is a number with a decimal point or a number in exponential form. 2.0, 256.4, 10.358, 7.64E+5, 5.56E-5 are all floats.
PHP automatically converts the variable to the correct data type, depending on its value. After declaring a variable it can be reused throughout the code. The assignment operator (=) used to assign value to a variable.
The syntax is covered in Variable variables. No, you are not "justified" in using this syntax. You should absolutely never do this, there is no good reason for using a number as a variable name.
Variables between brackets are considered valid (variable variables), no matter the syntax.
${'sad asda sda'} = 444;
echo ${'sad asda sda'};
// still works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With