PHP: Finding duplicates in multidimensional arrays and echo'ing the result -


i've been stuck little while , can find on internet how remove duplicates. i'm new php simple answers appreciated.

so let's have multidimensional array of surnames, addresses, time of accidents , reason of accidents so:

array(     array(     'adams','king street 12','14:25','heart attack'     ),     array(     'ellis','vine street 4','02:48','broken leg'     ),     array(     'adams','parker street 43','20:10','heart attack'     ) ) 

and need find entries have had same accident more once, of short array, output should this:

adams   king street 12   14:25   heart attack adams   parker street 43   20:10   heart attack 

i tried $answer = array_unique(array_diff_assoc($whole_ar, array_unique( $whole_ar))); doesn't seem work on multidimensional arrays.

i guess have in steps firstly need php5.5 or higher put array_column() on each key

$myarray = array(     array(     'adams','king street 12','14:25','heart attack'     ),     array(     'ellis','vine street 4','02:48','broken leg'     ),     array(     'adams','parker street 43','20:10','heart attack'     ) ); 

next call , find duplicates of first key (names)

$name = array_column($myarray, '0'); $address = array_column($myarray, '1'); $time = array_column($myarray, '2'); $injury = array_column($myarray, '3'); 

next count occurences

$count_names = array_count_values($name); 

do each criteria

then select apropriate arrays using if construct,

if ($count_names > 0){ ... } 

finaly select apropriate data rows using result of if construct


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -