我已閱讀並試圖將幾乎所有的remove從嵌套數組線程是在那裏重複值,我相信這個問題是,我試圖刪除整個輕微的獨特從一個(非常)大的多維數組中複製分支。我想這是更多的從數組中刪除重複數組類型的問題?刪除重複嵌套數組
我這裏有上Pastebin轉儲看看。我正在嘗試使用一個受保護的方法,我打電話給superUnique來解除這些咒語,但它不起作用(顯示在下面)。我究竟做錯了什麼?
/**
* @param $array
* @param bool $preserveKeys
* @param array $hashes
* @return array
*/
protected function superUnique($array, $preserveKeys = false, $hashes = array())
{
$uniqueArray = array();
foreach ($array AS $key => $value)
{
if (TRUE === is_array($value))
{
$hash = md5(serialize($value));
if (FALSE === isset($hashes[$hash]))
{
$hashes[$hash] = $hash;
$uniqueArray[$key] = $this->superUnique($value, $preserveKeys, $hashes);
} else {
// skip it i guess ?? should be a duplicate
}
} else {
if ($preserveKeys)
{
$uniqueArray[$key] = $value;
} else {
$uniqueArray[] = $value;
}
}
}
return $uniqueArray;
}
下面是示出了基於引擎收錄口是心非高水平,因爲它是運行的代碼,並在陣列
$output = $this->superUnique($output, 1);
foreach ($output AS $num => $arr)
{
// turns a multidim array to an object recursively
$obj = $this->arrToObj($arr);
if (isset($obj->message->body))
{
echo "Arr#: {$num}\n";
echo "Time: {$obj->attributes->timestamp}\n";
echo "Body: {$obj->message->body}\n\n\n";
}
}
die;
這是我的輸出的一個切片的口是心非的例子陣列。
Arr#: 172
Time: 2013-06-25T16:34:46-0700
Body: ok, so we decided on everything then?
Arr#: 173
Time: 2013-06-25T16:34:46-0700
Body: ok, so we decided on everything then?
Arr#: 174
Time: 2013-06-25T16:34:46-0700
Body: ok, so we decided on everything then?
Arr#: 175
Time: 2013-06-25T16:34:46-0700
Body: ok, so we decided on everything then?
Arr#: 176
Time: 2013-06-25T16:34:59-0700
Body: yes, see you tomorrow
Arr#: 177
Time: 2013-06-25T16:34:59-0700
Body: yes, see you tomorrow
Arr#: 178
Time: 2013-06-25T16:34:59-0700
Body: yes, see you tomorrow
Arr#: 179
Time: 2013-06-25T16:34:59-0700
Body: yes, see you tomorrow
Arr#: 180
Time: 2013-06-25T16:35:38-0700
Body: are you still onlne?
Arr#: 181
Time: 2013-06-25T16:36:10-0700
Body: hey bob
爲什麼'//跳過it'?刪除它 – vladkras
您可以這樣做:http://stackoverflow.com/a/946300/945775 – AgmLauncher
可能重複[如何從PHP中的多維數組中刪除重複的值](http://stackoverflow.com/questions/307674/how-to-remove-duplicate-values-from-a-multi-dimensional-array-in-php) – AgmLauncher