The print() function outputs one or more strings.
It is not actually a real function (it is a language construct) so you are not required to use parentheses with its argument list.
The major differences to echo() are that print only accepts a single argument and always returns 1.
[table caption=”” width=”100%” colwidth=”15%|15%|15%|55%” colalign=”left|lef|lef|left”]
Name, Required /Optional, Value Type, Description
strings , Required, String , It is the string for which is to be parsed.
[/table]
print() always Returns 1.
<?php print "Hi to all!"; // with parantheses print "\n"; print ("Hi to all!"); // without parantheses print "\n"; // multiple lines text print "This text spans in multiple lines. This text spans in multiple lines."; print "\n"; //using new line character print "This text \nspans in multiple lines. This text spans in \nmultiple lines. This spans\nmultiple lines. The newlines will be\noutput as well."; print "\n"; //using escaping character print "\n"; print "escaping characters is done \"Like this\"."; ?>
See below is the output of above code in Web browser.
Hi to all!
Hi to all!
This text spans
in multiple lines. This text
spans in multiple lines.
This text
spans in multiple lines. This text spans in
multiple lines.
This spans
multiple lines. The newlines will be
output as well.
escaping characters is done “Like this”.
<?php $strName = "Name"; $strValue = "Test"; print "$strName is $strValue"; ?>
See below is the output of above code in Web browser.
Name is Test
<?php $age=array("Arnav"=>"6"); print "Arnav is " . $age['Arnav'] . " years old."; ?>
See below is the output of above code in Web browser.
<?php $strName = "Arnav"; print 'Name is $strName'; ?>
See below is the output of above code in Web browser.
Name is $strName
<?php $strName = "Arnav"; print "Name is $strName"; // If you are not using any other characters, you can just print variables print "\n"; print $strName; ?>
See below is the output of above code in Web browser.
When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…
In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…
In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…
In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…
When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…
In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…