$offset = $value; } } public function offsetExists($offset) { return isset($this->$offset); } public function offsetUnset($offset) { unset($this->$offset); } public function offsetGet($offset) { return isset($this->$offset) ? $this->$offset : null; } } class emptyClass {} $arr = array( 'qwe' => 'qweqweqweqw', 'asd' => 'Привет!', // check UTF-8 chars 'zxccvx' => 'sdfsecvyh6bug6yfty', 1=>2, '2'=>2, 44, new cl1(), '%'=>'%$%$%', ); $arr = new cl1(); $arr[5] = 55; $arr['strstr'] = 'strstrstrstrstrstr'; //$arr = new emptyClass(); //$arr = array(); $q = new MyClass(); var_export($arr); //$q->loopArray($arr); // Works for objects and arrays $q->loopObject($arr); //$q->loopObject($arr);