Jump to content

[SOLVED] echo or print


Dirty-Rockstar

Recommended Posts

There is a difference between the two, but speed-wise it should be

irrelevant which one you use.  print() behaves like a function in that

you can do:  $ret = print "Hello World";And $ret will be 1That means

that print can be used as part of a more complex expression where echo

cannot.  print is also part of the precedence table which it needs to

be if it is to be used within a complex expression. It is just about at

the bottom of the precendence list though.  Only "," AND, OR and XOR

are lower.echo is marginally faster since it doesn't set a return value

if you really want to get down to the nitty gritty.If the grammar is:

echo expression [, expression[, expression] ... ]Then echo (

expression, expression ) is not valid.  ( expression ) reduces to just

an expression so this would be valid: echo ("howdy"),("partner");but

you would simply write this as: echo "howdy","partner"; if you wanted

to use two expression.  Putting the brackets in there serves no purpose

since there is no operator precendence issue with a single expression

like that.

Link to comment
Share on other sites

i understand, but for simple db queries and updates using print or echo to display the information does it really matter?

 

i was taught on print, and to avoid echo all the times for what im coding anyway, which is not too complaicated. just queries, updates and inserts into 1 db then displaying that information based on certain variables and results

 

here is an example of a snippit of code from a forum i made

 

 


$ID=$_GET[iD];

$user1="SELECT * FROM {$db_prefix}question where id='$ID'";
$user2=mysql_query($user1) or die(mysql_error());
$user3=mysql_fetch_array($user2);

print "Choose the Topic you want to move this thread to<br>
Topic is:<br />
$user3[topic]<br />";

 

 

i ended print but in the code it continues. could i use echo to get the same result?

 

Link to comment
Share on other sites

good practice would be this:

 

echo 'Choose the Topic you want to move this thread to<br>Topic is:<br />'.$user3[topic].'<br />';

 

You don't have to use echo, but look at my formatting.

 

No it isn't... you are using a constant as the array index. It will work because PHP makes it a string with the value of the constants name if it isn't set. It gives you an E_NOTICE. Do $user3['topic'] instead.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.