Minzer Posted June 2, 2021 Share Posted June 2, 2021 Havent posted here in a while, been learning lots but im stuck on trying to unset/replace arrays that contain awkward key values. [0] => 2021-06-02T19:40:00Z [1] => 2021-06-03T02:10:00Z [2] => 2021-06-03T01:10:00Z [3] => 2021-06-02T23:05:00Z [4] => 2021-06-02T23:05:00Z [5] => 2021-06-02T23:07:00Z [6] => 2021-06-02T23:20:00Z [7] => 2021-06-02T18:20:00Z [8] => 2021-06-03T00:10:00Z [9] => 2021-06-03T00:40:00Z The json Im using is constantly updated, not sure why tmrw's dates June 3rd are at the top for their API design =[ Not good at regex. preg_replace/etc. Im desperate id use array search manually if I knew how to simple parse out tmrw's dates. I have unlimited API calls so I reckon it don't matter, here's what Ive been playing with $oddsdata = 'https://pinnacle.datafeeds.net/api/json/odds/pinnacle/v3/60/baseball/mlb/moneyline?api-key=a71b8fe8e9eb957db549aaa5d99797a4'; $readodds = file_get_contents($oddsdata); $odds = json_decode($readodds, true); $today = date("Y-m-d"); $tmrw = date('Y-m-d', strtotime( $today . " +1 days")); foreach($odds['games'] as $key => $val): $gidRE[$key]["gid"] = $val["gameUID"]; $startOdds[$key]["start"] = $val["startDate"]; $homeTeams[$key]["hteam"] = $val["homeTeam"]; $awayTeams[$key]["ateam"] = $val["awayTeam"]; $Price[$key]["betPrice"] = $val["betPrice"]; $BookOdds[$key]["book"] = $val["sportsbook"]; $BetName[$key]["betName"] = $val["betName"]; $Live[$key]["Live"] = $val["isLive"]; endforeach; $endgidd = end(array_keys($gidRE)) + '1'; $endz = end(array_keys($odds['games'])); for ($l = 0; $l < $endz; ++$l) { $OddsAll[] = array_merge($gidRE[$l], $startOdds[$l], $homeTeams[$l], $awayTeams[$l], $Price[$l], $BetName[$l]); } Quote Link to comment https://forums.phpfreaks.com/topic/312844-filter-php-array-from-json/ Share on other sites More sharing options...
Solution Barand Posted June 2, 2021 Solution Share Posted June 2, 2021 Since you want to filter an array, I suggest array_filter() $times = [ '2021-06-02T19:40:00Z', '2021-06-03T02:10:00Z', '2021-06-03T01:10:00Z', '2021-06-02T23:05:00Z', '2021-06-02T23:05:00Z', '2021-06-02T23:07:00Z', '2021-06-02T23:20:00Z', '2021-06-02T18:20:00Z', '2021-06-03T00:10:00Z', '2021-06-03T00:40:00Z' ]; $d = new DateTime('23:59:59', new DateTimeZone('Z')); $newtimes = array_filter($times, function($v) use ($d) { return new DateTime($v) <= $d; }); 1 1 Quote Link to comment https://forums.phpfreaks.com/topic/312844-filter-php-array-from-json/#findComment-1586975 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.