The use of quotes is independent of the framework, that is to say that this is a characteristic of the PHP language, the use of quotation marks is to specify a literal type String, when declaring Strings in PHP there are not only those two forms for do it, but there are 4 ways:
- Simple quotation marks
- Double quotes
- Syntax heredoc
- Syntax nowdoc (since PHP 5.3.0)
Simple Quoting
This is the most basic way to declare strings.
Example:
$a = 'Stack Overflow'
$b = 'Car\'s'
Unlike double-quote and heredoc syntax, variables and escape statements for special characters will not be expanded when they are enclosed within a single quote string. That is to say that \n
and $a
will be shown as literal strings.
Double Quoting
If a string is delimited with double quotes ("), PHP will interpret the following escape sequences as special characters:
The most important feature of the double quotes of a string is the fact that variable names are expanded. That is, "$a"
will show the value assigned to $a
and not $ a as a literal string, example:
$a = 3;
echo "$a"; //Mostrará 3 y no $a
In conclusion, single quotes display the text as it is defined, and the use of double quotes interprets special characters and also expands the value of the variables to display it.
Going to your question, both forms are fine, if you wanted to have the variable array indexes for example you could use double quotes to define something like:
["categorias_$id"=>$categoria] //Si por ejemplo $id = 1 obtendrías categorias_1
Although the above could also be done with single quotes as follows:
['categorias_'.$id =>$categoria]
However, this could make the code somewhat illegible in case you concatenate more values.
For more information on the other ways to define strings, check the official PHP documentation link
The following English OS question can also be useful link