浏览数(9723)
【PHP-switch条件类型、排序】
例1:$a=array(0,707,708,'ssid');
$b=array();foreach ($a as $key => $value) { switch ((string)$value) { case 'ssid': $c='ssid'; break; case 0: $c='sindex'; break; case 707: $c='login'; break; case 708: $c='register'; break; } if(!isset($b[$c])){ $b[$c]=array(); }}print_r($b);
结果:array('sinde'=>array(),'login'=>array(),'register'=>array(),'ssid'=>array())
例2:$a=array(0,707,708,'ssid');
$b=array();foreach ($a as $key => $value) { switch ($value) { case 'ssid': $c='ssid'; break; case 0: $c='sindex'; break; case 707: $c='login'; break; case 708: $c='register'; break; } if(!isset($b[$c])){ $b[$c]=array(); }}print_r($b);
结果:array('sinde'=>array(),'login'=>array(),'register'=>array())
例3:$a=array(0,707,708,'ssid');
$b=array();foreach ($a as $key => $value) { switch ((string)$value) { case 0: $c='sindex'; break; case 707: $c='login'; break; case 708: $c='register'; break; case 'ssid': $c='ssid'; break; } if(!isset($b[$c])){ $b[$c]=array(); }}print_r($b);
结果:array('sinde'=>array(),'login'=>array(),'register'=>array())
PHP中switch,十点睡觉。有时间分析源码再看细节