0

i have associate array like this :

$json_data = array();
$jason_data[]= array ('id'=>'1','brand'=>'chanel','name'=>'red');
$jason_data[]= array ('id'=>'3','brand'=>'lacoste','name'=>'green');
$jason_data[]= array ('id'=>'1','brand'=>'chanel','name'=>'red');

$jason_data[0] and $jason_data[2] are Equal

i want find in $jason_data for equal array and echo them

samayo
  • 16,163
  • 12
  • 91
  • 106
Reza Mazarlou
  • 2,986
  • 4
  • 22
  • 31

1 Answers1

0

I don't know whats the context of this and your question is vague, but anyway, I hope this is what you want to achieve. (and your variable naming is odd). In your example index zero and two are the same, and since they are multi-dimensional, you can flatten them in a way by using serialize. Try this:

$json_data = array();
$json_data[]= array ('id'=>'1','brand'=>'chanel','name'=>'red');
$json_data[]= array ('id'=>'3','brand'=>'lacoste','name'=>'green');
$json_data[]= array ('id'=>'1','brand'=>'chanel','name'=>'red');

$json_data = array_map('serialize', $json_data);
$values = array_count_values($json_data);

echo '<pre>';
foreach($values as $array => $count) {
    if($count > 1) {
        $array = unserialize($array);
        print_r($array);
    }
}

Should output/print the ones that has duplicates:

Array
(
    [id] => 1
    [brand] => chanel
    [name] => red
)
user1978142
  • 7,946
  • 3
  • 17
  • 20