I usually do this in PHP for better readability but I don’t know if it consumes memory or has any other issues? Let’s say I have this code:
$user = getUser(); // getUser() will return an array
I could do:
$email = $user["email"];
sendEmail($email);
Without declaring the variable $email I could do:
sendEmail($user["email"]);
Which one is better? Consider that this is just a very simple example.
Don’t make your code less readable just to save a few bytes. And this will not save you more, even if
$emailis a 100 MB string, because internally PHP uses the copy on write mechanism: The content of a variable is not copied unless you change it.Example: