0

I'm returning a page slug created with two string variables like this in PHP:

$result = $site_url . '/' . $final_slug;
return $result;

But I've noticed that someone online did it like this:

return "$site_url/$final_slug";

Is the second version valid too, because it seems to work in my code?

Lisa
  • 115
  • 11
  • 3
    Yes, as your attempts surely showed yourself. – Ulrich Eckhardt Aug 19 '22 at 12:12
  • 5
    Does this answer your question? [What is the difference between single-quoted and double-quoted strings in PHP?](https://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php) – Ulrich Eckhardt Aug 19 '22 at 12:13
  • 1
    [PHP string interpolation syntax](https://stackoverflow.com/a/43437427) – 001 Aug 19 '22 at 12:14
  • If you use double quotes for a string, then the **$** is interpreted and variables are expanded. For instance "$var1$var2" is also perfectly valid. – Rohit Gupta Aug 30 '22 at 01:44

0 Answers0