最后输出怎么多了个→呢??
<?php
function gostrsplit($str) {
$str_array = explode(",",$str);
for ($j = 0; $j < count($str_array); $j++) {
if ($j != count($str_array)){
print $str_array[$j].'→';
}else {
print $str_array[$j];
}
}
}
echo gostrsplit("1,2,3");
?>
function gostrsplit($str) {
$str_array = explode(",",$str);
for ($j = 0; $j < count($str_array); $j++) {
if ($j != count($str_array)){
print $str_array[$j].'→';
}else {
print $str_array[$j];
}
}
}
echo gostrsplit("1,2,3");
?>
作者: wanhui1827 发布时间: 2011-06-16
PHP code
function gostrsplit($str) { // $str_array = explode(",",$str); // for ($j = 0; $j < count($str_array); $j++) { //这里都己经是小于了,当然是不会等的了 // if ($j != count($str_array)){ //这里不会等,所以永远都输出这个 // print $str_array[$j].'→'; // }else { // print $str_array[$j]; // } // // } echo implode('→', explode(',', $str)); //其实一句话就能实现了,多看手册 } echo gostrsplit("1,2,3");
作者: yangball 发布时间: 2011-06-16
回避问题不是好办法,虽然有时很有效
if ($j != count($str_array)-1){
由 for ($j = 0; $j < count($str_array); $j++) {
决定, 循环内 $ij 不可能等于 count($str_array)
if ($j != count($str_array)-1){
由 for ($j = 0; $j < count($str_array); $j++) {
决定, 循环内 $ij 不可能等于 count($str_array)
作者: xuzuning 发布时间: 2011-06-16
引用 1 楼 yangball 的回复:
PHP code
function gostrsplit($str) {
// $str_array = explode(",",$str);
// for ($j = 0; $j < count($str_array); $j++) { //这里都己经是小于了,当然是不会等的了
// if ($j != count($str_array)){ //这里不会等,所以永远都输出……
PHP code
function gostrsplit($str) {
// $str_array = explode(",",$str);
// for ($j = 0; $j < count($str_array); $j++) { //这里都己经是小于了,当然是不会等的了
// if ($j != count($str_array)){ //这里不会等,所以永远都输出……
谢谢,我是想要这样的效果
if ( ( $i_week == $weekarray[$arrayAttenddate[0]] || $i_week == $weekarray[$arrayAttenddate[1]] || $i_week == $weekarray[$arrayAttenddate[2]] ) ) {
}
这里面的$arrayAttenddate[1]是explode分割出来的 是不是还是得靠循环来解决呢,谢谢了。
作者: wanhui1827 发布时间: 2011-06-16