Please tell me what I am doing wrong, when the php file executes is saves the actual folder as "$name" instead of Peter. What am I doing wrong?
Here is my code:
$name = "Peter";
copy_directory('you/','dir/$name');
Please tell me what I am doing wrong, when the php file executes is saves the actual folder as "$name" instead of Peter. What am I doing wrong?
Here is my code:
$name = "Peter";
copy_directory('you/','dir/$name');
You'll need to use double quotes in order for the variable to be interpreted as Peter
copy_directory('you/',"dir/$name");
You need to use double quotes if you want to expand variables within a string.
$name = "Peter";
copy_directory('you/',"dir/$name");
Or, alternately, concatenate the variable onto the string:
copy_directory('you/','dir/' . $name);
Use double quotes instead of single quotes;
$name = "Peter"; copy_directory('you/',"dir/$name");
Or alternatively, concatenate the variable;
$name = "Peter"; copy_directory('you/','dir/' . $name);
Problem is that you use the '
but should use there ""
or 'dir/'. $name
:
copy_directory('you/','dir/$name');
It's good practice to use concatenation operator while using php variables.
copy_directory('you/','dir/'.$name);
Updated Answer:
This could be big debate what to use. It's everyone's own opinion. But people say we should avoid complexity of double quotes. Double quotes have memory save issues. It doesn't matter for small values. So I thought it's good practice to use concatenation operator while using php variables.