-1

私はこのような配列を持っています:

Array
(
    [0] => Saturday 19th January 2013 07:59:57 PM
    [1] => Sunday 20th January 2013 07:00:26 PM
    [2] => Monday 21st January 2013 02:08:15 PM
    [3] => Monday 21st January 2013 02:11:00 PM
    [4] => Monday 21st January 2013 02:41:02 PM
    [5] => Monday 21st January 2013 02:42:14 PM
    [6] => Monday 21st January 2013 03:03:34 PM
    [7] => Monday 21st January 2013 03:07:39 PM
    [8] => Monday 21st January 2013 03:37:11 PM
    [9] => Monday 21st January 2013 03:37:52 PM
    [10] => Monday 21st January 2013 04:14:08 PM
    [11] => Monday 21st January 2013 04:16:38 PM
    [12] => Monday 21st January 2013 04:19:18 PM
    [13] => Monday 21st January 2013 05:45:17 PM
    [14] => Monday 21st January 2013 06:39:04 PM
    [15] => Monday 21st January 2013 08:01:56 PM
    [16] => Monday 21st January 2013 08:03:23 PM
    [17] => Monday 21st January 2013 08:12:15 PM
    [18] => Monday 21st January 2013 08:15:20 PM
    [19] => Monday 21st January 2013 08:29:57 PM
    [20] => Monday 21st January 2013 09:57:25 PM
    [21] => Tuesday 22nd January 2013 01:57:59 AM
    [22] => Tuesday 22nd January 2013 06:39:34 AM
    [23] => Tuesday 22nd January 2013 11:38:25 AM
    [24] => Tuesday 22nd January 2013 03:21:08 PM
    [25] => Tuesday 22nd January 2013 04:09:36 PM
}

この配列をグループ化して、次のようにします。

Array
(
    [Saturday 19th January 2013 07:59:57 PM] => 1
    [Sunday 20th January 2013 07:00:26 PM] => 1
    [Monday 21st January 2013 02:08:15 PM] => 19
    [Tuesday 22nd January 2013 01:57:59 AM] => 5
   }

ここで、キーは 20 ~ 23 文字に一致する前の配列からの一致した値である必要があり、値は前の配列からの一致した値の数です。どんな助けにも感謝します!

4

1 に答える 1

2

これは機能します (ただし、新しい配列は時間を保持しませんが、これが望ましい場合があります)。

$array = array('Saturday 19th January 2013 07:59:57 PM', 'Sunday 20th January 2013 07:00:26 PM', 'Monday 21st January 2013 02:08:15 PM', 'Monday 21st January 2013 02:11:00 PM', 'Monday 21st January 2013 02:41:02 PM', 'Monday 21st January 2013 02:42:14 PM', 'Monday 21st January 2013 03:03:34 PM', 'Monday 21st January 2013 03:07:39 PM', 'Monday 21st January 2013 03:37:11 PM', 'Monday 21st January 2013 03:37:52 PM', 'Monday 21st January 2013 04:14:08 PM', 'Monday 21st January 2013 04:16:38 PM', 'Monday 21st January 2013 04:19:18 PM', 'Monday 21st January 2013 05:45:17 PM', 'Monday 21st January 2013 06:39:04 PM', 'Monday 21st January 2013 08:01:56 PM', 'Monday 21st January 2013 08:03:23 PM', 'Monday 21st January 2013 08:12:15 PM', 'Monday 21st January 2013 08:15:20 PM', 'Monday 21st January 2013 08:29:57 PM', 'Monday 21st January 2013 09:57:25 PM', 'Tuesday 22nd January 2013 01:57:59 AM', 'Tuesday 22nd January 2013 06:39:34 AM', 'Tuesday 22nd January 2013 11:38:25 AM', 'Tuesday 22nd January 2013 03:21:08 PM', 'Tuesday 22nd January 2013 04:09:36 PM');

foreach ($array as $date)
{

  $name = date('l jS F Y', strtotime($date));

  if (!isset($newArray[$name]))
  {
    $newArray[$name] = 1;
  }

  else
  {
    ++$newArray[$name];
  }

}

print_r($newArray);

時間が必要な場合は、これを使用します。

foreach ($array as $date)
{

  $name = date('l jS F Y', strtotime($date));

  $time = substr($date, -11);

  if (!isset($times[$name]))
  {
    $newArray[$name . ' ' . $times[$name] = $time] = 1;
  }

  else
  {
    ++$newArray[$name . ' ' . $times[$name]];
  }

}
于 2013-03-29T21:12:48.063 に答える