0

I have a two-element array - $time

echo 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)

How convert each element of $time array to timestamp?

echo var_dump($time) should look like:

array
  0 => 
    array
      'otw' => timestamp 'timestampvalue' (length=)
      'zam' => timestamp 'timestampvalue' (length=)
 1 => 
    array
      'otw' => timestamp 'timestampvalue' (length=)
      'zam' => timestamp 'timestampvalue' (length=)
bilasek
  • 77
  • 2
  • 4
  • 2
    Have a look at array_walk_recursive() – Jonathan Jul 31 '12 at 13:57
  • You're not expecting us to code a solution for you, are you? Maybe take a good look at the documentation: http://php.net/manual/en/function.array-walk-recursive.php –  Jul 31 '12 at 14:02

2 Answers2

4

simply use 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
});
MarcDefiant
  • 6,649
  • 6
  • 29
  • 49
0

Or using array_map()

function arrayToTimestamps($array)
{
    return array(strtotime($array['otw']), strtotime($array['zam']));
}
$newArray = array_map('arrayToTimestamps', $array);
Jonathan
  • 2,968
  • 3
  • 24
  • 36