- abs: documentation ( source)
- print_r: documentation ( source)
- strtotime: documentation ( source)
<?php
function getClosest($search, $arr) {
$closest = null;
foreach ($arr as $item) {
if ($closest === null || abs($search - $closest) > abs($item - $search)) {
$closest = $item;
}
}
return $closest;
}
$days = array ('monday','wednesday','saturday');
for($i=0; $i<sizeof($days);$i++){
$d[$i]=strtotime($days[$i]);
}
print_r($d);
die();