Welcome! Log In Create A New Profile

Advanced

Print and Echo

Posted by Brad_78160642 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Print and Echo
August 06, 2013 04:51PM
I've discovered you can print or echo variables with text without having to concatenate if you use the double quotes. Here's an example I found on php.net

Language: PHP
// You can use variables inside of an echo statement $foo = "foobar"; $bar = "barbaz";   echo "foo is $foo"; // foo is foobar   // You can also use arrays $baz = array("value" => "foo");   echo "this is {$baz[';value';]} !"; // this is foo !   // Using single quotes will print the variable name, not the value echo ';foo is $foo';; // foo is $foo

Thought that was pretty cool, the code colouring doesn't work in my editor if I include the variable in my quotes but still good to know.
Links: echo, print
Re: Print and Echo
August 06, 2013 04:56PM
Re: Print and Echo
August 06, 2013 05:06PM
Print and echo will actually work the same in the example I gave but I named the post with the hope someone would bring up the difference between the two. Thanks.
avatar Re: Print and Echo
August 06, 2013 09:09PM
Print returns a value (0 or 1), echo does not.

Echo can take multiple arguments, print can only take a single argument.

Echo is marginally faster than print.

In normal use there is no real practical difference between the two.
Re: Print and Echo
August 07, 2013 03:27PM
Very interesting, thanks for sharing!
So print actually returns a value - now I'm wondering what would be a practical application this
avatar Re: Print and Echo
August 07, 2013 03:59PM
There seems to be some uncertainty whether print returns 1 or 0, or always returns 1, depending on which source you refer to.
In any event, can't see any practical use for it.
avatar
Mac
Re: Print and Echo
August 07, 2013 05:17PM
Re: Print and Echo
August 09, 2013 03:50PM
Thank you for the link Mac.

I have noticed from video tutorials that many programmers prefer to use echo. But since it doesn't really make such a big difference and you can do more with print, I think for now I will continue using print instead of echo.

Regards
E
Re: Print and Echo
August 13, 2013 12:44PM
On chapter 2 of the notes that we received on a CD they say: "Another way to display things on the page is to use an alternative to print() – echo( )".

I prefer to use echo(); because I think it is cool and I saw most qualified programmers use it instead of print();

Another question that I have is that, in the notes they said when we use print or echo should be followed by () but I realised that most people and in the prescribed book they don't use () though I haven't experienced errors when I use echo with(). What is your advice Prof?
avatar Re: Print and Echo
August 13, 2013 01:49PM
avatar
Mac
Re: Print and Echo
August 13, 2013 01:54PM
Yes, as in the link. It is personal preference. Why add tags when you can type less?
Sorry, only registered users may post in this forum.

Click here to login