Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用写在多行上的字符串声明PHP数组_Php_Arrays_String - Fatal编程技术网

用写在多行上的字符串声明PHP数组

用写在多行上的字符串声明PHP数组,php,arrays,string,Php,Arrays,String,PHP允许在多行上声明字符串,如下所示: $s = <<<EOS Hello World! EOS; $s=您当然可以: <?php $a = array(<<<EOS foo bar! EOS , // comma here is important <<<EOS bar foo! EOS ); // closing the array on a separate line is im

PHP允许在多行上声明字符串,如下所示:

$s = <<<EOS
    Hello
    World!
EOS;
$s=您当然可以:

<?php
$a = array(<<<EOS
    foo
    bar!
EOS
, // comma here is important
<<<EOS
    bar
    foo!
EOS
); // closing the array on a separate line is important

print_r($a);
当然,您可以:

<?php
$a = array(<<<EOS
    foo
    bar!
EOS
, // comma here is important
<<<EOS
    bar
    foo!
EOS
); // closing the array on a separate line is important

print_r($a);

我对长文本使用模板:

     $data = array(file_get_contents('file1.txt'),  
file_get_contents('file2.txt')
    );



 print_r($data);exit;
file1.txt内容

“示例行1”

file2.txt内容

“样本行2 行尾


我对长文本使用模板:

     $data = array(file_get_contents('file1.txt'),  
file_get_contents('file2.txt')
    );



 print_r($data);exit;
file1.txt内容

“示例行1”

file2.txt内容

“样本行2 行尾


删除
从阵列中删除
EOS
之后是的,它还通过删除所有的;在EOS之后!谢谢@PES002我得到了错误和/或错误的输出,没有如我的回答中所示的额外修改。@MonkeyZeus我没有看到任何错误,但是输出被窃听了。因此,您确实需要添加coma和
(数组结束)到单独的行+1对于您,我正在使用PHP7.0.5在进行测试,并将数组关闭在与关闭EOS相同的行上,如下所示
EOS),生成分析错误。删除
从阵列中删除
EOS
之后是的,它还通过删除所有的;在EOS之后!谢谢@PES002我得到了错误和/或错误的输出,没有如我的回答中所示的额外修改。@MonkeyZeus我没有看到任何错误,但是输出被窃听了。因此,您确实需要添加coma和
(数组结束)到单独的行+1对于您,我正在使用PHP7.0.5在进行测试,并将数组关闭在与关闭EOS相同的行上,如下所示
EOS),生成一个分析错误。哦,是的,它正在工作!没有尝试在单独的行中使用逗号!谢谢哦,是的,它起作用了!没有尝试在单独的行中使用逗号!谢谢