fork(2) download
  1. <?php
  2.  
  3. $posts = array(
  4. array('date' => '7/30/10', 'title' => 'july post'),
  5. array('date' => '7/19/10', 'title' => 'another post in july'),
  6. array('date' => '7/22/10', 'title' => 'sup, this will be with another post')
  7. );
  8.  
  9. $new_posts = array();
  10.  
  11. foreach( $posts as $post ) {
  12. $week = date('W', strtotime($post['date']));
  13.  
  14. if( !isset($new_posts[$week]) ) {
  15. $new_posts[$week] = array();
  16. }
  17.  
  18. $new_posts[$week][] = $post;
  19. }
  20.  
  21. print_r($new_posts);
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
Array
(
    [30] => Array
        (
            [0] => Array
                (
                    [date] => 7/30/10
                    [title] => july post
                )

        )

    [29] => Array
        (
            [0] => Array
                (
                    [date] => 7/19/10
                    [title] => another post in july
                )

            [1] => Array
                (
                    [date] => 7/22/10
                    [title] => sup, this will be with another post
                )

        )

)