وظيفة print() في PHP

مثال

كتابة النص إلى الناتج:

<?php
print "I love Shanghai!";
?>

Run Instance

التعريف والاستخدام

الوظيفة print() تخرج إحدى أو أكثر من النصوص.

التعليقات:الوظيفة print() ليست وظيفة فعليًا، لذا لا تحتاج إلى استخدام الأقواس معها.

Tip:print() function is slower than echo() Slower.

Syntax

print(strings)
Parameters Description
strings Required. Send one or more strings to the output.

Technical Details

Return value: Always returns 1.
PHP Version: 4+

More Examples

Example 1

Output the value of a string variable (str):

<?php
$str = 'I love Shanghai!';
print $str;
?>

Run Instance

Example 2

Output the value of a string variable ($str), including HTML tags:

<?php
$str = 'I love Shanghai!';
print $str;
print '<br>What a nice day!';
?>

Run Instance

Example 3

Connect two string variables:

<?php
$str1 = 'I love Shanghai!';
$str2='What a nice day!';
print $str1 . ' ' . $str2;
?> 

Run Instance

Example 4

Output the value of an array:

<?php
$age=array("Bill"=>"60");
print 'Bill Gates is ' . $age['Bill'] . ' years old.';
?>

Run Instance

Example 5

Output text:

<?php
print 'This text'
spans multiple
lines.";
?> 

Run Instance

Example 6

The difference between single quotes and double quotes. Single quotes will output the variable name, not the value:

<?php
$color = 'red';
print 'Roses are $color';
print '<br>';
print 'Roses are $color';
?>

Run Instance