What are the differences between passing $1 as a string and as a variable in PHP functions?
When passing $1 as a string in a PHP function, it will be treated as the literal value "$1" rather than a variable. To pass $1 as a variable, you need to use double quotes around the string to allow for variable interpolation. This way, PHP will recognize $1 as a variable and evaluate its value.
// Passing $1 as a string
function exampleFunction($param) {
echo $param;
}
exampleFunction('$1'); // Output: $1
// Passing $1 as a variable
function exampleFunction($param) {
echo $param;
}
$variable = '$1';
exampleFunction($variable); // Output: 1