0

我有一个二元素数组 - $time

回声 var_dump($time) :

array
  0 => 
    array
      'otw' => string '12:00' (length=5)
      'zam' => string '15:00' (length=5)
 1 => 
    array
      'otw' => string '16:00' (length=5)
      'zam' => string '18:00' (length=5)

如何将 $time 数组的每个元素转换为时间戳?

echo var_dump($time) 应该如下所示:

array
  0 => 
    array
      'otw' => timestamp 'timestampvalue' (length=)
      'zam' => timestamp 'timestampvalue' (length=)
 1 => 
    array
      'otw' => timestamp 'timestampvalue' (length=)
      'zam' => timestamp 'timestampvalue' (length=)
4

2 回答 2

4

只需使用array_walk_recursive

array_walk_recursive($your_array, function(&$element) {
  // notice: this will use the date of today and add the time to it.
  $element = strtotime($element);
  // $element = strtotime($element, 0); // use 1.1.1970 as current date
});
于 2012-07-31T14:00:57.883 回答
0

或使用 array_map()

function arrayToTimestamps($array)
{
    return array(strtotime($array['otw']), strtotime($array['zam']));
}
$newArray = array_map('arrayToTimestamps', $array);
于 2012-07-31T14:01:53.803 回答