>  기사  >  백엔드 개발  >  这个数组如何用for循环出来

这个数组如何用for循环出来

WBOY
WBOY원래의
2016-06-23 13:39:421072검색

记住,前提必须是for循环,不要别的方法循环,切记!
Array
(
    [0] => /dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50e9c339938f7f013cc1170a321f6458.jpg::::::/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50e9c339938f7f013cc1170a321f6458.jpg::::::
    [1] => /dgcms/d/file/product/yysj/gdjcpt/2015-02-15/71d522fdc9305d0d6f4cc6735e8035c4.jpg::::::/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/71d522fdc9305d0d6f4cc6735e8035c4.jpg::::::
    [2] => /dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50700eff01cc0fd13fdbfe8cc0863222.jpg::::::/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50700eff01cc0fd13fdbfe8cc0863222.jpg::::::
)
我只想循环出这个二维数组中的每一组数组中的第一个,


回复讨论(解决方案)

??是一???。

估?你是要??效果。

$arr = array(    '/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50e9c339938f7f013cc1170a321f6458.jpg::::::/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50e9c339938f7f013cc1170a321f6458.jpg::::::',    '/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/71d522fdc9305d0d6f4cc6735e8035c4.jpg::::::/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/71d522fdc9305d0d6f4cc6735e8035c4.jpg::::::',    '/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50700eff01cc0fd13fdbfe8cc0863222.jpg::::::/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50700eff01cc0fd13fdbfe8cc0863222.jpg::::::');for($i=0,$len=count($arr); $i<$len; $i++){    $tmp = explode('::::::', $arr[$i]);    echo $tmp[0].'<br>';}


/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50e9c339938f7f013cc1170a321f6458.jpg
/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/71d522fdc9305d0d6f4cc6735e8035c4.jpg
/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50700eff01cc0fd13fdbfe8cc0863222.jpg

??是一???。

估?你是要??效果。

$arr = array(    '/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50e9c339938f7f013cc1170a321f6458.jpg::::::/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50e9c339938f7f013cc1170a321f6458.jpg::::::',    '/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/71d522fdc9305d0d6f4cc6735e8035c4.jpg::::::/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/71d522fdc9305d0d6f4cc6735e8035c4.jpg::::::',    '/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50700eff01cc0fd13fdbfe8cc0863222.jpg::::::/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50700eff01cc0fd13fdbfe8cc0863222.jpg::::::');for($i=0,$len=count($arr); $i<$len; $i++){    $tmp = explode('::::::', $arr[$i]);    echo $tmp[0].'<br>';}


/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50e9c339938f7f013cc1170a321f6458.jpg
/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/71d522fdc9305d0d6f4cc6735e8035c4.jpg
/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50700eff01cc0fd13fdbfe8cc0863222.jpg




具体到实际问题
为啥我也是这样写的,只能输出一个图片呢
<?phpif($bqr['morepic']){$morepic=$bqr['morepic'];$rexp="rn";$fexp="::::::";$rr=explode($rexp,$morepic);$count=count($rr);$morpic="";for($i=0;$i<$count;$i++){$j=$i+1;$fr=explode($fexp,$rr[$i]);$smallpic=$fr[0]; //小图$bigpic=$fr[1]; //大图             $morpic .="<li class='active'><i></i><img  src='".$smallpic."'    style="max-width:90%"  style="max-width:90%" alt="这个数组如何用for循环出来" ><b></b></li>";              }                          echo $morpic;}?>

$rexp="rn";


??是一???。

估?你是要??效果。

$arr = array(    '/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50e9c339938f7f013cc1170a321f6458.jpg::::::/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50e9c339938f7f013cc1170a321f6458.jpg::::::',    '/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/71d522fdc9305d0d6f4cc6735e8035c4.jpg::::::/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/71d522fdc9305d0d6f4cc6735e8035c4.jpg::::::',    '/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50700eff01cc0fd13fdbfe8cc0863222.jpg::::::/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50700eff01cc0fd13fdbfe8cc0863222.jpg::::::');for($i=0,$len=count($arr); $i<$len; $i++){    $tmp = explode('::::::', $arr[$i]);    echo $tmp[0].'<br>';}


/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50e9c339938f7f013cc1170a321f6458.jpg
/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/71d522fdc9305d0d6f4cc6735e8035c4.jpg
/dgcms/d/file/product/yysj/gdjcpt/2015-02-15/50700eff01cc0fd13fdbfe8cc0863222.jpg




具体到实际问题
为啥我也是这样写的,只能输出一个图片呢
<?phpif($bqr['morepic']){$morepic=$bqr['morepic'];$rexp="rn";$fexp="::::::";$rr=explode($rexp,$morepic);$count=count($rr);$morpic="";for($i=0;$i<$count;$i++){$j=$i+1;$fr=explode($fexp,$rr[$i]);$smallpic=$fr[0]; //小图$bigpic=$fr[1]; //大图             $morpic .="<li class='active'><i></i><img  src='".$smallpic."'    style="max-width:90%"  style="max-width:90%" alt="这个数组如何用for循环出来" ><b></b></li>";              }                          echo $morpic;}?>



你的$rexp="rn";   是$rexp="\r\n";   吗?  用rn分割,你确定图片地址中不会出现 rn?
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.