[ create a new paste ] login | about

Link: http://codepad.org/ghrLWrsW    [ raw code | output | fork ]

PHP, pasted on Jul 27:
<?php

$mysql = array
(
	array('name' => 'I', 'date' => '20110804'),
	array('name' => 'J', 'date' => '20110805'),
	array('name' => 'F', 'date' => '20110801'),
	array('name' => 'D', 'date' => '20110730'),
	array('name' => 'B', 'date' => '20110728'),
	array('name' => 'G', 'date' => '20110802'),
);

$eventful = array
(
	array('name' => 'L', 'date' => '20110807'),
	array('name' => 'A', 'date' => '20110727'),
	array('name' => 'E', 'date' => '20110731'),
	array('name' => 'H', 'date' => '20110803'),
	array('name' => 'K', 'date' => '20110806'),
	array('name' => 'C', 'date' => '20110729'),
);

$dates = array();
$result = array_merge($mysql, $eventful);

foreach ($result as $key => $value)
{
	$dates[$key] = $value['date'];
}

array_multisort($dates, SORT_ASC, $result);

$result = array_chunk($result, 4);

print_r($result);

?>


Output:
Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [name] => A
                    [date] => 20110727
                )

            [1] => Array
                (
                    [name] => B
                    [date] => 20110728
                )

            [2] => Array
                (
                    [name] => C
                    [date] => 20110729
                )

            [3] => Array
                (
                    [name] => D
                    [date] => 20110730
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [name] => E
                    [date] => 20110731
                )

            [1] => Array
                (
                    [name] => F
                    [date] => 20110801
                )

            [2] => Array
                (
                    [name] => G
                    [date] => 20110802
                )

            [3] => Array
                (
                    [name] => H
                    [date] => 20110803
                )

        )

    [2] => Array
        (
            [0] => Array
                (
                    [name] => I
                    [date] => 20110804
                )

            [1] => Array
                (
                    [name] => J
                    [date] => 20110805
                )

            [2] => Array
                (
                    [name] => K
                    [date] => 20110806
                )

            [3] => Array
                (
                    [name] => L
                    [date] => 20110807
                )

        )

)


Create a new paste based on this one


Comments: