私は多次元配列を持っています。リターン配列に重複が含まれています
$wd = array_unique($arr);
$d = array_diff($arr, $wd);
print_r($d);
しかし、それは唯一の1次元配列と出力すべての重複のために働く:私が得た最も近いでした。これをどうやってやるの?所望の出力の
例:
配列の場合:
array(
[1] => (
[u] => test1u
[d] => test1d
)
[2] => (
[u] => test2u
[d] => test2d
)
[3] => (
[3] => test3u
[3] => test3d
)
[1] => (
[u] => test1u
[d] => test1d
)
)
がarray([1] => ([u] => test1u [d] => test1d))
を返す必要があり、アレイがある場合:
array(
[1] => (
[u] => test1u
[d] => test1d
)
[2] => (
[u] => test2u
[d] => test2d
)
[3] => (
[3] => test3u
[3] => test3d
)
[1] => (
[u] => test1u
[d] => test1d
)
[2] => (
[u] => test2u
[d] => test2d
)
)
が返すべきarray([1] => ([u] => test1u [d] => test1d)[2] => ([u] => test2u [d] => test2d))
が、配列の場合:
array(
[1] => (
[u] => test1u
[d] => test1d
)
[2] => (
[u] => test2u
[d] => test2d
)
[3] => (
[3] => test3u
[3] => test3d
)
[1] => (
[u] => test1u
[d] => test1d
)
[2] => (
[u] => test2u
[d] => test2d
)
[1] => (
[u] => test1u
[d] => test1d
)
)
それだけ返す必要がありますarray([1] => ([u] => test1u [d] => test1d))
EDIT:配列は$arr = json_decode($arr);
から来て、オリジナルのJSONが重複していたので
は、配列内のエントリが重複していますエントリ。 jsonをデコードせずにこれを行うより良い方法がある場合は、教えてください。
これは検索プログラムの一部として使用されています。 JSONは、検索用語の1つの条件を満たすソース配列のすべてのエントリの配列です。最も重複しているエントリを維持することは、それらのエントリがすべての検索用語ではないにしてもその大部分を含むことを保証する。ここ
は、JSONのデコードされたファイルです。この場合は[{"1":[{"u":"testing","d":"2017\/04\/27","st":"Test","i":"roses","v":"1","t":"org","sp":"N\/A","k":"0","img":"--"}]},{"2":[{"u":"testing","d":"2017\/04\/27","st":"Test","i":"roses","v":"1","t":"org","sp":"N\/A","k":"0","img":"--"}]},{"5":[{"u":"testing","d":"2017\/04\/27","st":"Test","i":"roses daffodil","v":"1","t":"org","sp":"N\/A","k":"0","img":"--"}]},{"3":[{"u":"testing","d":"2017\/04\/27","st":"Test","i":"daffodil","v":"1","t":"org","sp":"N\/A","k":"0","img":"--"}]},{"4":[{"u":"testing","d":"2017\/04\/27","st":"Test","i":"daffodil","v":"1","t":"org","sp":"N\/A","k":"0","img":"--"}]},{"5":[{"u":"testing","d":"2017\/04\/27","st":"Test","i":"roses daffodil","v":"1","t":"org","sp":"N\/A","k":"0","img":"--"}]},{"6":[{"u":"testing","d":"2017\/04\/27","st":"Test","i":"roses daffodil","v":"1","t":"org","sp":"N\/A","k":"0","img":"--"}]}]
このJSONは「バラの水仙」
可能であれば、var_export()を実行して質問を更新すると参考になります。 –
重複キーを持つ1つの配列はどのようになりますか? – hassan
配列内に同じキーのインスタンスが複数ある場合、それらは上書きされます。インデックスは一意でなければなりません。 – Qirel