Php 字符串数组元素打印在新行中
这是我的密码:Php 字符串数组元素打印在新行中,php,arrays,Php,Arrays,这是我的密码: <?php function spilt($number){ $array = array("john doe alex hales johnny johnn arnold ronnie", "john doe alex hales johnny johnn arnold ronnie", "john doe alex hales johnny johnn arnold ronnie");
<?php
function spilt($number){
$array = array("john doe alex hales johnny johnn arnold ronnie",
"john doe alex hales johnny johnn arnold ronnie",
"john doe alex hales johnny johnn arnold ronnie");
for ($i=0; $i <count($array) ; $i++) {
$string = explode(" ", $array[$i]);
echo"<br>";
for ($j = 0; $j < count($string); $j++) {
echo $string[$j]." ";
if ($j+1 == $number ) {
echo "<br>";
}
}
}
}
spilt(3);
john
doe
alex
hales
johnny
johnn
arnold
ronnie
john doe
alex hales
johnny johnn
arnold ronnie
john doe alex
hales johnny johnn
arnold ronnie
有可能吗?你唯一的问题是:
如果($j+1==$number)
该条件意味着您仅在$j+1
正好等于$number
时插入新行。您需要查看它是否可以被$number
整除
if (($j + 1) % $number == 0)
我不明白,你有什么问题?你已经给出了结果和你的代码,但是不应该发生的事情是这样的,反之亦然。只要使用。我的代码运行得很好,我只想当我传递值到函数时,所有数组元素都会根据我传递的值断开。我想要的输出我已经写在上面了。我不知道怎么解决它。代码运行良好我的代码运行良好-那么你就没有问题了,或者你没有在你的OP.bro中适当地解释它。你能根据我想要的输出帮助我吗@谢谢你的回答。我很忙。不客气。