Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Echo string with multiple variables

Tags:

html

php

All of the following commands work but which one is considered correct in terms of security, compatibility, speed, and other conventions?

//one
echo "$row->first_name $row->last_name <br />";

//two
echo $row->first_name . ' ' . $row->last_name .'<br />';

//three
echo $row->first_name;
echo $row->last_name;
echo '<br />';
like image 678
CyberJunkie Avatar asked Dec 04 '22 21:12

CyberJunkie


1 Answers

Although not one of the styles you specified, I recommend using braces for echo-ing strings, mostly on compatibility note.

echo "Welcome back, {$row->first_name} {$row->last_name}";

More information about this type of syntax can be found in PHP Strings.

like image 76
drfranks3 Avatar answered Dec 07 '22 22:12

drfranks3