我有一个具有重复项(zxcas)的数组,但键 [result] 和 [size] 的值不同:
Array
(
[0] => Array
(
[file] => asda.txt
[path] => /home/user/public_html/asda.txt
[type] => .txt
[size] => 13
[status] => new
)
[1] => Array
(
[file] => zxcas.txt
[path] => /home/user/public_html/zxcas.txt
[type] => .txt
[size] => 35
[status] => new
)
[2] => Array
(
[file] => AS
[path] => /home/user/public_html/AS.txt
[type] => .txt
[size] => 3
[status] => deleted
)
[3] => Array
(
[file] => zxcas.txt
[path] => /home/user/public_html/zxcas.txt
[type] => .txt
[size] => 29
[status] => deleted
)
)
我将如何编写一个执行以下操作的函数:
- 通过键 [path] 的值检测重复数组
- 取消设置重复项之一
- 将键 [status] 的值更改为“已修改”。
最终数组应如下所示:
Array
(
[0] => Array
(
[file] => asda.txt
[path] => /home/user/public_html/asda.txt
[type] => .txt
[size] => 13
[status] => new
)
[1] => Array
(
[file] => AS
[path] => /home/user/public_html/AS.txt
[type] => .txt
[size] => 3
[status] => deleted
)
[2] => Array
(
[file] => zxcas
[path] => /home/user/public_htmlzxcas.txt
[type] => .txt
[size] => 29
[status] => modified
)
)
到目前为止我的代码:
$newArray = array();
$fillerArray = array();
foreach($diff AS $key => $value)
{
if(!in_array($value['path'], $fillerArray))
{
$fillerArray[] = $value['path'];
$newArray[] = $value;
}
}
return $newArray;
目前它只删除重复的 zxcas,但不重命名值状态。我该怎么做?