这是一个例子。
public function jscss($module)
{
if (is_array($module))
{
foreach ($module as $val)
{
$this->jscss($val);
}
return;
}
if ( ! $module)
{
return;
}
if(in_array($module, $this->_loaded_jscss_modules)) return;
array_push($this->_loaded_jscss_modules, $module);
$this->_loaded_jscss_modules = array_flip(array_flip($this->_loaded_jscss_modules)); // <-- Right this part where i am talking about
$aSrc = array();
//css
foreach($this->_jscss_modules as $key => $val)
{
if(in_array($key, $this->_loaded_jscss_modules) && isset($val['css']) )
foreach($val['css'] as $css)
$aSrc[] = '<link rel="stylesheet" href="'.$css.'" type="text/css" />';
}
//js
foreach($this->_jscss_modules as $key => $val)
{
if(in_array($key, $this->_loaded_jscss_modules) && isset($val['js']) )
foreach($val['js'] as $js)
$aSrc[] = '<script type="text/javascript" src="'.$js.'"></script>';
}
$vars['jscss_src'] = "\n".implode("\n",$aSrc)."\n";
$this->vars($vars);
}
您可以在我评论过的地方看到使用了两次的 array_flip。为什么使用函数 array_flip 两次?