woss

Array delete

Oct 29th, 2011
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.44 KB | None | 0 0
  1. <?php
  2.  
  3. class Config {
  4.  
  5.     private $_config = array();
  6.  
  7.     public function delete ($name) {
  8.  
  9.         $name =& $this->_get_item($name);
  10.  
  11.         unset($name);
  12.  
  13.     }
  14.  
  15.     private function & _get_item ($name) {
  16.  
  17.         $config =& $this->_config;
  18.  
  19.         foreach (array_map("trim", explode(".", $name)) as $group) {
  20.  
  21.             if ( ! array_key_exists($group, $config) ) $config[$group] = array();
  22.  
  23.             $config =& $config[$group];
  24.  
  25.         }
  26.  
  27.         return $config;
  28.  
  29.     }
  30.  
  31. }
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment