怎么根据参数来获取相应的变量

WBOY
Release: 2016-06-13 12:19:20
Original
1201 people have browsed it

如何根据参数来获取相应的变量?
我用ajax传递了一个参数到后台
$v=$_POST[ ' v ' ];
然后执行一个函数 aaa($v);
function aaa($fun){
     //我想在这里global一个变量 global哪个变量我也是不知道的  是根据$fun来的,$fun只是字符串而已,
    如果$fun==a那么就global $a  如果$fun==b那么就global $b 参数名和变量名是相等的
    但你不能写这样的判断
    if($fun=='a'){
        global $a;
    }
    因为$fun的值不是固定的那么几个,可能会增加或更改
    我知道参数和变量不是一个概念但我想实现这个效果
}
------解决思路----------------------
你直接  global $$fun;  不行?php 好像是可以的

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!