Home >Backend Development >PHP Tutorial >php里如何把循环数组赋值给字符串变量

php里如何把循环数组赋值给字符串变量

WBOY
WBOYOriginal
2016-06-13 11:56:261681browse

php里怎么把循环数组赋值给字符串变量

本帖最后由 u014203582 于 2014-05-03 14:03:16 编辑 比如说
    $contents = curl_exec($ch);<br />  <br />	preg_match_all("/<td>(.*)<\/td>/",$contents,$arr);<br />	for($i=0;$i<=100;$i++)<br />		{<br />			 <br />			print_r($arr[1][$i]);<br />			if (($i + 1) % 1 ==0)<br />			{	echo '<br/>';	}<br />		}


我现在不要打印$arr,而是把它放到字符串变量中
------解决方案--------------------
$txt = '';<br />for($i=0;$i<=100;$i++) {<br />  $txt .= $arr[1][$i]);<br />  if (($i + 1) % 1 ==0) {<br />    $txt .=  '<br/>';<br />  }<br />}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn