php中echo简单用法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php中echo简单用法相关的知识,希望对你有一定的参考价值。

初学者,被echo语法困扰,查看,求各位大神指点!!!

手册上写echo — 输出一个或多个字符串,而字符串有单引号,双引号以及定界符。

单引号只会输出字符本身,双引号会输出变量,手册上写的已经很详细了。

 

<?php
echo "Hello World";

echo "This spans
multiple lines. The newlines will be
output as well";
//
echo "This spans\nmultiple lines. The newlines will be\noutput as well.";
//
echo "Escaping characters is done \"Like this\".";

// 你可以在回声语句里面使用变量
$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 !

// 使用单引号将打印变量名,而不是值
echo ‘foo is $foo‘; // foo is $foo

// 如果您没有使用任何其他字符,您可以只返回变量
echo $foo;          // foobar
echo $foo,$bar;     // foobarbarbaz

// 字符串可以作为多个参数单独传递或连接在一起并作为一个参数传递
echo ‘This ‘, ‘string ‘, ‘was ‘, ‘made ‘, ‘with multiple parameters.‘, chr(10);
echo ‘This ‘ . ‘string ‘ . ‘was ‘ . ‘made ‘ . ‘with concatenation.‘ . "\n";
//
echo <<<END
This uses the "here document" syntax to output
multiple lines with $variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon. no extra whitespace!
END;

// 因为回声不象一个函数,下面的代码是无效的。
($some_var) ? echo ‘true‘ : echo ‘false‘;

// 然而,下面的例子将工作:
($some_var) ? print ‘true‘ : print ‘false‘; // print is also a construct, but
                                            // it behaves like a function, so
                                            // it may be used in this context.
echo $some_var ? ‘true‘: ‘false‘; // changing the statement around
?>

 

我自己写的代码

echo "{$match[0][0]}"."\n"."{$match[0][1]}"."\n"."{$match[0][2]}"."\n"."{$match[0][3]}"."\n"."{$match[0][4]}";

echo "{$match[0][0]}","\n","{$match[0][1]}","\n","{$match[0][2]}","\n","{$match[0][3]}","\n","{$match[0][4]}";

//可见,不同的字符表变量可以用英文.|,隔开,在加上转义符,这样每输出一个数组就换一行,要输出数组的话,最好用大括号包括。

只能作为连续字符串输出

echo ‘wo zai zhe‘."\n".‘huanhang‘;
















































以上是关于php中echo简单用法的主要内容,如果未能解决你的问题,请参考以下文章

Php中的goto用法

PHP匿名类的用法

php session的用法

简单分析PHP中序列化用法介绍

PHP中的ob_start用法详解

PHP 中的有效性和用法 =+