輸出指定的值,除了索引方式還有其它方式嗎?
public function index(){ $new = $this->index_com(); //輸出指定的值 echo $new[2];}public function index_com(){ $list = 'a'; $category = 'b'; $totalCount = 'c'; $current = 'd'; return array($list, $category, $totalCount, $current);}
回複內容:
輸出指定的值,除了索引方式還有其它方式嗎?
public function index(){ $new = $this->index_com(); //輸出指定的值 echo $new[2];}public function index_com(){ $list = 'a'; $category = 'b'; $totalCount = 'c'; $current = 'd'; return array($list, $category, $totalCount, $current);}
還可以是字典,
public function index(){ $new = $this->index_com(); //輸出指定的值 echo $new[list];}public function index_com(){ $list = 'a'; $category = 'b'; $totalCount = 'c'; $current = 'd'; return array('list'=>$list, 'category'=>$category);}
public function index(){ $new = $this->index_com($k); //輸出指定的值 echo $new;}public function index_com($k){ $arr=['list'=>a,'category'=>'c']; return $arr[$k];
使用list文法可以達到你想要的效果:
public function index(){ list($list, $category, $totalCount, $current) = $this->index_com(); //輸出指定的值 echo $category;}public function index_com(){ $list = 'a'; $category = 'b'; $totalCount = 'c'; $current = 'd'; return array($list, $category, $totalCount, $current);}