phparraystimemultiplicationdatetime-conversion

Multiply each integer in a flat array by 60


I have an array called $times. It is a list of small numbers (15,14,11,9,3,2). These will be user submitted and are supposed to be minutes. As PHP time works on seconds, I would like to multiply each element of my array by 60.

I've been playing around with array_walk and array_map but I can't get those working.


Solution

  • Just iterate over the array with the foreach statement and multiply:

    foreach ($times as $value) {
    
      $new_times[] = $value * 60;
    
    }