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

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

WBOY
Release: 2016-06-13 11:56:26
Original
1666 people have browsed it

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 />		}
Copy after login


我现在不要打印$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 />}
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template