Spliting one hour into four equal part


This question already has an answer here:


Use below code:-

function getInterval($time='01:00'){ 
    $res = [];   
    $startTime = new DateTime($time);
    for($i=0; $i<4;$i++){
        $res[] = $startTime->format("H:i A").'<br>'; 
        $startTime->add(new DateInterval('PT15M'));
    return $res;

$result = getInterval('01:00');
echo '<pre>'; print_r($result);

As you have mentioned in your comment, you have an array like this ['10:00 am','11:00 am','12:00 pm','1:00 pm'], then use below code.

$arr = ['10:00 am','11:00 am','12:00 pm','1:00 pm'];
foreach($arr as $record){
    $ampm = explode(' ',$record)[1];    
    $time = explode(':',$record)[0];
    for($i=0; $i<4;$i++){
       $res[] = "$time:".($i*15 == 0?"00":$i*15)." $ampm";
echo '<pre>'; print_r($res);

Hope it will help you :-)

Need Your Help

Create a duplicate copy of Linked list in O(n) time

c# c++ c algorithm

A link list is given with two pointer, 1st is pointing to next node and another is random pointer. Random pointer is pointing to any node of LinkedList. Write a complete program to create a copy of

Understanding npm's "skippingAction Module is inside a symlinked module"

node.js selenium npm protractor

I am trying to force the version of selenium-webdriver and protractor using npm's package.json for that purpose but I get the following error message: