Php > Arrays
A simple function for loading an array with an object
A simple function for loading an array with an object // Function for loading an array with an object. I tried loading the array by // setting $event_object equal to the object, which didn't seem to return the right // values for later use. // I ended up pushing objects (using array_push($_name_of_array_, // $_object_or_value_to_push_) ). This enable me to use the return the $event_list // array in a usable form. function getEvents($filename) { //string $filename $event_list = array(); $event_object = new event(); $i = 0; @ $fp = fopen($filename, "r"); if(!$fp) { echo "
Cannot open ".$filename." for reading mode...
"; exit; } while(!feof($fp)) { $temp = fgetcsv($fp, 1024, ":"); if(!$temp) break; $event_object->init($temp[0],$temp[1],$temp[2],$temp[3],$temp[4], $temp[5],$temp[6],$temp[7],$temp[8]); if(!array_push($event_list, $event_object)) break; } fclose($fp); return $event_list; }
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage