Rumah > pembangunan bahagian belakang > tutorial php > 这个数组如何用for循环出来

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

WBOY
Lepaskan: 2016-06-23 13:39:42
asal
1137 orang telah melayarinya

记住,前提必须是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>';}
Salin selepas log masuk
Salin selepas log masuk
Salin selepas log masuk


/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>';}
Salin selepas log masuk
Salin selepas log masuk
Salin selepas log masuk


/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;}?>
Salin selepas log masuk
Salin selepas log masuk

$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>';}
Salin selepas log masuk
Salin selepas log masuk
Salin selepas log masuk


/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;}?>
Salin selepas log masuk
Salin selepas log masuk




你的$rexp="rn";   是$rexp="\r\n";   吗?  用rn分割,你确定图片地址中不会出现 rn?
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan