php 动态调用方法

$searchActionArr = [
  '1' => 'searchAlbumList',
  '2' => 'searchUser',
  '3' => 'searchActivityList',
];
if(filled($searchActionArr[$searchType]) && method_exists($this,$searchActionArr[$searchType])){
  $instanceMethod = $searchActionArr[$searchType];
  $result = $this->$instanceMethod($searchName);
  result = $this->{$searchActionArr[$searchType]}($searchName);
}

或 使用“{}”,参考在php中{}的作用 

if(filled($searchActionArr[$searchType]) && method_exists($this,$searchActionArr[$searchType])){
  result = $this->{$searchActionArr[$searchType]}($searchName);
}

 

posted @ 2022-11-16 17:50  哦一哦啊啊  阅读(161)  评论(0编辑  收藏  举报