Split an array of strings into 2, use one as key and the other as value php -
i have athe following array of strings: (var_dump result)
array(17) { [15]=> string(14) "07-04-16 10:00" [16]=> string(14) "07-04-16 10:30" [6]=> string(13) "07-04-16 8:00" [0]=> string(14) "08-04-16 13:00" [1]=> string(14) "08-04-16 13:30" [7]=> string(14) "12-04-16 16:00" [8]=> string(14) "12-04-16 16:30" [9]=> string(14) "12-04-16 17:00" [10]=> string(14) "12-04-16 17:30" [11]=> string(14) "12-04-16 18:00" [12]=> string(14) "12-04-16 18:30" [13]=> string(14) "12-04-16 19:00" [14]=> string(14) "12-04-16 19:30" [2]=> string(14) "13-04-16 11:30" [3]=> string(14) "13-04-16 12:00" [4]=> string(14) "13-04-16 12:30" [5]=> string(14) "13-04-16 13:00" }
is there way split values on " ", use left portion key , right portion value? i'm trying without overwriting values have like:
"07-04-16" => "10:00","10:30"
thanks
just loop, explode , append times date index:
foreach($array $value) { list($date, $time) = explode(' ', $value); $result[$date][] = $time; }
Comments
Post a Comment