vurentjie Posted May 30, 2009 Share Posted May 30, 2009 hi just a quick question, some code for what I am trying... further up ..... self::$_menus['test'] = array(); self::loadLinks($links,'test'); public static function loadLinks($links){ $linkmark = false; $where = array_slice( func_get_args(), 1 ); foreach($where as $resource){ $linkmark=($linkmark===false)?self::$_menus[$resource]:$linkmark[$resource]; } $linkmark['newlink']='testinglink'; var_dump($linkmark); var_dump(self::$_menus); } it seems the menu array is not being passed by reference, if I convert all static class vars and use &$this->.... I can reference properly.... $this->_menus['test'] = array(); $this->loadLinks($links,'test'); public function loadLinks($links){ $linkmark = false; $where = array_slice( func_get_args(), 1 ); foreach($where as $resource){ $linkmark=($linkmark===false)?&$this->_menus[$resource]:&$linkmark[$resource]; } $linkmark['newlink']='testinglink'; var_dump($linkmark); var_dump($this->_menus); } I thought php5 would handle this as reference? Can anyone give me a why? Link to comment https://forums.phpfreaks.com/topic/160288-array-references-php-5/ Share on other sites More sharing options...
vurentjie Posted May 30, 2009 Author Share Posted May 30, 2009 well i ended up just sticking to the follwing...works fine... public function loadLinks($links){ $linkmark = false; $where = array_slice( func_get_args(), 1 ); foreach($where as $resource)($linkmark===false)? $linkmark = &$this->_menus[$resource] : $linkmark = &$linkmark[$resource]; $linkmark = ( is_array($linkmark) ) ? array_merge($linkmark,$links) : $links; } Link to comment https://forums.phpfreaks.com/topic/160288-array-references-php-5/#findComment-845895 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.