加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – CodeIgniter – 无限参数?

发布时间:2020-12-13 22:01:30 所属栏目:PHP教程 来源:网络整理
导读:我目前正在使用CodeIgniter. 我正在尝试编写一个可以使用无限数量的参数的函数. 所以在控制器中它会是这样的 function test($name,$others){ foreach($others){ //do something }} 我可以称之为 example.com/control/test/some name/param1/param2/param3/pa
我目前正在使用CodeIgniter.

我正在尝试编写一个可以使用无限数量的参数的函数.

所以在控制器中它会是这样的

function test($name,$others){
    foreach($others){
       //do something
    }
}

我可以称之为

example.com/control/test/some name/param1/param2/param3/param4/param5...

我怎么设置它?

解决方法

您可以使用 URI class中的uri_to_assoc函数获取关联的URI段数组.因此,在控制器中,您可能会执行以下操作:

function test($name){
    $uri_seg = $this->uri->uri_to_assoc(4);

    foreach($uri_seg as $para){
        // Do something with each of the URI segments passed in here after $name
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读