Home >Backend Development >PHP Tutorial >这个数组如何用for循环出来

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

WBOY
WBOYOriginal
2016-06-23 13:39:421122browse

记住,前提必须是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?
Statement:
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