eval.in

Paste #9598

PHP — PHP 5.4.6, pasted 1 year ago

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
<?php


$data = array(
		0 => Array ( "id" => 47523, "date" => "12-02-13 14:36:32" ),
		1 => Array ( "id" => 47523, "date" => "12-02-13 13:56:48" ),
		2 => Array ( "id" => 38639, "date" => "12-02-13 13:38:51" ),
		3 => Array ( "id" => 38639, "date" => "12-02-13 13:07:43" ),
);


	$data = array_reduce($data, function($a,$b){
		isset($a[$b['id']]) or $a[$b['id']] = $b;
		return $a;
	});
	
	print_r(array_values($data));
?>

Program Output

Array
(
    [0] => Array
        (
            [id] => 47523
            [date] => 12-02-13 14:36:32
        )

    [1] => Array
        (
            [id] => 38639
            [date] => 12-02-13 13:38:51
        )

)

OK (0.008 sec real, 0.010 sec wall, 13 MB, 166 syscalls)

Fork