How to search id into array and club together in php -
ok i'm stuck, i've been working on array merge finding id array .i want find subjectid array if found merge both array , calulate actual hour in time , time(calculate timing in between). array code.. actual array:
array ( [eventlist] => array ( [0] => array ( [allday] => false [id] => {83ae8778-a604-46f1-94be-a045f2a9b548} [subjectid] => 2 [roomid] => 2 [fromtime] => 00:30 [totime] => 01:45 [plottingtype] => research ) [1] => array ( [allday] => false [id] => {2b1f7b32-6d44-4700-8c50-f030b94d41f6} [roomid] => 2 [fromtime] => 00:00 [totime] => 00:45 [plottingtype] => research ) [2] => array ( [allday] => false [id] => {83ae8778-a604-46f1-94be-a045f2a9b548} [subjectid] => 3 [roomid] => 2 [fromtime] => 00:30 [totime] => 01:45 [plottingtype] => admin ) ) ) expected output: array ( [eventlist] => array ( [0] => array ( [time] => 01:15 [plottingtype] => research ) [2] => array ( [time] => 00:15 [plottingtype] => admin ) ) )
please suggest me appropriate solution..
well should foreach through of them
$array; // array $new_array = array(); // empty new array $new_array['eventlist'] = array(); foreach($array['eventlist'] $inner) { if(isset($inner['subjectid']) { // work out maths time difference , put $interval $fromtime = new datetime($inner['fromtime']); $totime = new datetime($inner['totime']); $interval = $fromtime->diff($totime); $interval = $interval->format('%h:%i'); $new_inner = array( "time" => $interval, "plottingtype" => $inner['plottingtype'] ); array_push($new_array['eventlist'], $new_inner); } }
while untested. should work php 5.4+
Comments
Post a Comment