Location: PHPKode > scripts > Multi-Dimensional Array Handler > multi-dimensional-array-handler/obj.marray.compressed.php
<?php /*********************************************
 * Script: Multi-Dimentional Array Handler (marray) Object | Author: Colin Jermain | Contact: http://phpknowhow.com/contact.php | Date: January 25th, 2008 | Version: 1.0
 * License: 
 *    Copyright (C) 2008 Colin Jermain
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*********************************************/
class marray {public $array;public function marray() {$this->array=array();}public function set($loc, $value) {$value=(is_array($value))?var_export($value, true):"'".addslashes($value)."'";eval("\$this->array".$this->loc($loc)."={$value};");}public function get($loc) {return eval("return \$this->array".$this->loc($loc).";");}public function loc($loc) {try {if($loc!="") {if(preg_match('/^[A-Za-z0-9_\-]+(,[A-Za-z0-9_\-]+)*$/i', $loc)) {return preg_replace('/^/', '[\'', preg_replace('/$/', '\']', preg_replace('/,/', '\'][\'', $loc)));} else {throw new Exception("Invalid location path for multi-dimentional array");}} else {return "";}} catch(Exception $e) {echo "<b>Fatal Error</b>: ".$e->getMessage()." on line ".$e->getLine()." of ".$e->getFile();exit();}}public function count($loc) {return eval("return count(\$this->array".$this->loc($loc).");");}public function is_empty($loc) {return eval("return empty(\$this->array".$this->loc($loc).");");}public function is_set($loc) {return eval("return isset(\$this->array".$this->loc($loc).");");}public function __toString() {return print_r($this->array, true);}}?>
Return current item: Multi-Dimensional Array Handler