php 一个数组分成几个数组
如何把这个数组根据000001到000023分成不同的数组。例如000001Array([0]=>../bin/000001_20130823124957823_0001...
如何把这个数组根据000001到000023分成不同的数组。
例如000001
Array ( [0] => ../bin/000001_20130823124957823_0001.jpg [1] => ../bin/000001_20130823124957948_0002.jpg [2] => ../bin/000001_20130823124957995_0003.jpg [3] => ../bin/000001_20130823124958120_0004.jpg [4] => ../bin/000001_20130823124958230_0005.jpg [5] => ../bin/000001_20130823124958339_0006.jpg )
000003
Array ( [0] => ../bin/000003_20130823124957823_0001.jpg [1] => ../bin/000003_20130823124957948_0002.jpg [2] => ../bin/000003_20130823124957995_0003.jpg [3] => ../bin/000003_20130823124958120_0004.jpg ) 展开
例如000001
Array ( [0] => ../bin/000001_20130823124957823_0001.jpg [1] => ../bin/000001_20130823124957948_0002.jpg [2] => ../bin/000001_20130823124957995_0003.jpg [3] => ../bin/000001_20130823124958120_0004.jpg [4] => ../bin/000001_20130823124958230_0005.jpg [5] => ../bin/000001_20130823124958339_0006.jpg )
000003
Array ( [0] => ../bin/000003_20130823124957823_0001.jpg [1] => ../bin/000003_20130823124957948_0002.jpg [2] => ../bin/000003_20130823124957995_0003.jpg [3] => ../bin/000003_20130823124958120_0004.jpg ) 展开
展开全部
遍历数组 用explode('_', $filename) 取到前面的那段作为键值如 ‘000001’ => '../bin/000001_....jpg'
如下所示:
$new_arr = array();
foreach ($arr as $key => $value) {
$tmp = explode('_', substr($value, strrpos($value, '/')+1));
$new_arr[$tmp[0]][] = $value;
}
//如果原来的数组没用了就unset掉
unset($arr);
如下所示:
$new_arr = array();
foreach ($arr as $key => $value) {
$tmp = explode('_', substr($value, strrpos($value, '/')+1));
$new_arr[$tmp[0]][] = $value;
}
//如果原来的数组没用了就unset掉
unset($arr);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询