I have an array that has a duplicate (zxcas), but with a different value for the key [result] and [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
)
)
How would I go about writing a function that does the following:
- Detects duplicates arrays by the value of the key [path]
- Unset one of the duplicates
- Change the value of key [status] to "modified".
The final array should look like:
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
)
)
My code so far:
$newArray = array();
$fillerArray = array();
foreach($diff AS $key => $value)
{
if(!in_array($value['path'], $fillerArray))
{
$fillerArray[] = $value['path'];
$newArray[] = $value;
}
}
return $newArray;
At the moment it only removes the duplicate zxcas, but does not rename the value status. How would I do that?