php print是函数吗,php print函数怎么用

php print函数用于输出一个或多个字符串,其语法是print(strings),参数strings必需,指发送到输出的一个或多个字符串。print()函数实际不是一个函数,所以您不必对它使用括号。

dfa6e8e2122fed8c30084124e5091102.png

php print函数怎么用?

定义和用法

print() 函数输出一个或多个字符串。

注释:print() 函数实际不是一个函数,所以您不必对它使用括号。

提示:print() 函数比 echo() 稍慢。

语法print(strings)

参数

strings必需。发送到输出的一个或多个字符串。

返回值:始终返回 1。

PHP 版本:4+

例子 1

输出字符串变量($str)的值:<?php

$str = "I love Shanghai!";

print $str;

?>

输出:I love Shanghai!

例子 2

输出字符串变量($str)的值,包含 HTML 标签:<?php

$str = "I love Shanghai!";

print $str;

print "
What a nice day!";

?>

输出:I love Shanghai!

What a nice day!

例子 3

连接两个字符串变量:<?php

$str1 = "I love Shanghai!";

$str2="What a nice day!";

print $str1 . " " . $str2;

?>

输出:I love Shanghai! What a nice day!

例子 4

输出数组的值:<?php

$age=array("Bill"=>"60");

print "Bill Gates is " . $age['Bill'] . " years old.";

?>

输出:Bill Gates is 60 years old.

例子 5

输出文本:<?php

print "This text

spans multiple

lines.";

?>

输出:This text spans multiple lines.

例子 6

单引号和双引号的区别。单引号将输出变量名称,而不是值:<?php

$color = "red";

print "Roses are $color";

print "
";

print 'Roses are $color';

?>

输出:Roses are red

Roses are $color

例子 7

向输出写入文本:<?php

print "I love Shanghai!";

?>

输出:I love Shanghai!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值