Jump to content

Filter Php Array from json


Go to solution Solved by Barand,

Recommended Posts

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"]; 

$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]);


Link to comment
Share on other sites

  • Solution

Since you want to filter an array, I suggest array_filter()

$times = [
$d = new DateTime('23:59:59', new DateTimeZone('Z'));
$newtimes = array_filter($times, function($v) use ($d) {
                                return new DateTime($v) <= $d;


  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.