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

WBOY
Release: 2016-06-23 13:57:31
Original
1419 people have browsed it

比如说

    $contents = curl_exec($ch);  	preg_match_all("/<td>(.*)<\/td>/",$contents,$arr);	for($i=0;$i<=100;$i++)		{			 			print_r($arr[1][$i]);			if (($i + 1) % 1 ==0)			{	echo '<br/>';	}		}
Copy after login


我现在不要打印$arr,而是把它放到字符串变量中


回复讨论(解决方案)

$txt = '';for($i=0;$i<=100;$i++) {  $txt .= $arr[1][$i]);  if (($i + 1) % 1 ==0) {    $txt .=  '<br/>';  }}
Copy after login

你附加  
 条件是 %1,也就是每项都加
所以不需要循环,直接 $txt = join('
', $arr[1]); 就可以了

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