Created
April 18, 2014 12:58
-
-
Save pipiscrew/11042943 to your computer and use it in GitHub Desktop.
[php] structured array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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