Skip to content

Instantly share code, notes, and snippets.

@pipiscrew
Created April 18, 2014 12:58
Show Gist options
  • Save pipiscrew/11042943 to your computer and use it in GitHub Desktop.
Save pipiscrew/11042943 to your computer and use it in GitHub Desktop.
[php] structured array
<?php
//$data sample
//"Apr 14 2018 02:38 AM",10,test,,1.00,Android,Apple,95,{ jsonTest : jsonTitle}
class StatsRecord {
public $date;
public $event_name;
public $app_version;
public $app_platform;
public $device;
public $user_id;
public $json_params;
}
$rows = explode(PHP_EOL, $data);
$ListOfRECS = array(StatsRecord);
$rec;
//for each line
for ($x=1; $x <= sizeof($rows); $x++){
$line = explode(",", $rows[$x]);
$rec = new StatsRecord();
$rec->date = $line[0];
$rec->event_name = $line[2];
$rec->app_version = $line[4];
$rec->app_platform = $line[5];
$rec->device = $line[6];
$rec->user_id = $line[7];
$rec->json_params = $line[8];
//add to array!
$ListOfRECS[] = $rec;
}
// var_dump($ListOfRECS);
for ($x=1; $x <= sizeof($ListOfRECS); $x++){
echo $ListOfRECS[$x]->device;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment