0

i have an array in php like the one given below

$each_session_time=array("2700","3356","3278","5452");

the issue is i want to convert each element in this array into time i tried using

date("h:i:s",$each_session_array);

but it didn't work because date function doesn't work with arrays... so can anyone help me in converting the each element into time....I shall be very thankful to you

 $each_session_time=array();
 for ($i=0; $i<sizeof($array_in_time_str) ; $i++) { 
$each_session_time[$i]=$array_out_time_str[$i]-$array_in_time_str[$i];
                                                  }
4
  • did you try array_map ?? Commented Aug 23, 2016 at 13:09
  • @AhmadHajjar no i dint try that Commented Aug 23, 2016 at 13:10
  • the input array is array of timestamps right? Commented Aug 23, 2016 at 13:11
  • @AhmadHajjar and now i want to convert the hour sec and minutes to minutes Commented Aug 23, 2016 at 13:19

2 Answers 2

1

If I understood your request, then this is what you need : using array_map here is a demo

  <?php

  $each_session_time=array(2700,33522,2222278,1111452);

  $res = array_map(function($elem){
      return date ("H:i:s",$elem);
  },$each_session_time);

  print_r($res);
  ?>
Sign up to request clarification or add additional context in comments.

11 Comments

You are welcome, if this solved your problem please accept the answer and give it a +1 :)
This will show time after $elem seconds passed since Unix Epoch start.
And in your example demo 2700 seconds is 12 hours, okaaaay.
@u_mulder that's true, he wanted to convert the given values into time format :)
@AhmadHajjar thank u sir u saved me alot of time..thankx alot is there any algo that should convert H:i:s to minutues only
|
0

you can try this.

$each_session_time=array("2700","3356","3278","5452");
foreach ($each_session_time as $key => $value) {
   $timeArray[] = date("h:i:s",$value);
}
echo "<pre>";print_r($timeArray);
Output:
Array
 (
  [0] => 06:15:00
  [1] => 06:25:56
  [2] => 06:24:38
  [3] => 07:00:52
 )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.