删除重复的项目从S3对象的PHP多维数组 [英] Remove duplicate items from S3 objects multi dimension array in php
本文介绍了删除重复的项目从S3对象的PHP多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下面的,因为它没有显示的方式排列一个问题,我希望它;
I am having a problem with the array below as it is not displaying the way I want it to;
Array
(
[0] => Array
(
[name] => Accounts.csv
[time] => 1396518749
[size] => 4685
[hash] => 4ddde7286adcbf06472a7d8f9987bf88
)
[1] => Array
(
[name] => Book1.xlsx
[time] => 1396436339
[size] => 9776
[hash] => 96f219be0397b240777969f8b3cbb711
)
[2] => Array
(
[name] => Documents/
[time] => 1396510415
[size] => 0
[hash] => d41d8cd98f00b204e9800998ecf8427e
)
[3] => Array
(
[name] => Documents/AdbWinApi.dll
[time] => 1396847400
[size] => 96256
[hash] => 47a6ee3f186b2c2f5057028906bac0c6
)
[4] => Array
(
[name] => ken header.pdf
[time] => 1396436334
[size] => 110772
[hash] => fe64e53a2237c7b84b08981ed2c0447a
)
[5] => Array
(
[name] => sp42471.exe
[time] => 1396527931
[size] => 128609088
[hash] => 1687428c91011b0c028f91d16593c5e7
)
)
我想去掉一些重复的项目,并按以下重组的输出;
I would like to remove some duplicate items and restructure the output as below;
Array
(
[0] => Array
(
[name] => Accounts.csv
[time] => 1396518749
[size] => 4685
[hash] => 4ddde7286adcbf06472a7d8f9987bf88
)
[1] => Array
(
[name] => Book1.xlsx
[time] => 1396436339
[size] => 9776
[hash] => 96f219be0397b240777969f8b3cbb711
)
[2] => Array
(
[name] => Documents
[time] => 1396510415
[size] => 0
[hash] => d41d8cd98f00b204e9800998ecf8427e
)
[3] => Array
(
[name] => ken header.pdf
[time] => 1396436334
[size] => 110772
[hash] => fe64e53a2237c7b84b08981ed2c0447a
)
[4] => Array
(
[name] => sp42471.exe
[time] => 1396527931
[size] => 128609088
[hash] => 1687428c91011b0c028f91d16593c5e7
)
)
我现在用的是code以下检索阵列。
I am using the code below to retrieve the array.
private function listFiles($bucket = null , $prefix = null) {
$ls = S3::getBucket($bucket, $prefix);
if(!empty($ls)) {
foreach($ls as $l) {
//print_r($ls);
$fname = str_replace($prefix,"",$l['name']);
$ftime = $l['time'];
$fsize = $l['size'];
$fhash = $l['hash'];
if(!empty($fname)) {
$rv[] = array('name' => $fname, 'time' => $ftime, 'size' => $fsize, 'hash' => $fhash);
//$rv[] = $fname;
}
}
}
if(!empty($rv)) {
return $rv;
}
}
我应该修改哪些部分得到上述结果。 注:我还是新来的数组的东西
What part should I modify to get the results above. NB: I am still new to the array stuff.
推荐答案
您可以继续这样。
$newarr=array();
foreach($yourarr as $k=>&$arr)
{
$v=$arr['name'];
if(strpos($v,'/')!==false)
{
$v=explode('/',$v);
if(isset($v[1]) && strlen($v[1])>0){}else{$arr['name']=$v[0];$newarr[]=$arr;}
}
else { $newarr[]=$arr;}
}
print_r($newarr);
输出:
OUTPUT :
Array
(
[0] => Array
(
[name] => Accounts.csv
[time] => 1396518749
[size] => 4685
[hash] => 4ddde7286adcbf06472a7d8f9987bf88
)
[1] => Array
(
[name] => Book1.xlsx
[time] => 1396436339
[size] => 9776
[hash] => 96f219be0397b240777969f8b3cbb711
)
[2] => Array
(
[name] => Documents
[time] => 1396510415
[size] => 0
[hash] => d41d8cd98f00b204e9800998ecf8427e
)
[3] => Array
(
[name] => ken header.pdf
[time] => 1396436334
[size] => 110772
[hash] => fe64e53a2237c7b84b08981ed2c0447a
)
[4] => Array
(
[name] => sp42471.exe
[time] => 1396527931
[size] => 128609088
[hash] => 1687428c91011b0c028f91d16593c5e7
)
)
这篇关于删除重复的项目从S3对象的PHP多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文