我有一个使用自己的参数的函数,但也检查是否有任何get / post值是avaliabe用于不同的行为。
我希望能够在主页上执行此操作,该网址为:domain.com /
例如:
function simulate_get($name,$val){
// do it
}
然后,在代码中
..
simulate('foo','last_posts');
show_user_posts($user,$bla,$ble);
..
我知道我应该在函数中添加一个额外的参数,但仍然想知道在PHP中是否真的可以做到这一点。
答案 0 :(得分:2)
请写信:
function simulate_get($name, $val)
{
$_GET[$name] = $val;
}
答案 1 :(得分:2)
由于 $ _ GET 是superglobal,您可以这样做:
$_GET['foo'] = 'last_posts';
然后直接在您的代码中使用它:
$_GET['foo'] = 'last_posts';
show_user_posts($user,$bla,$ble);
或者如果你想使用一个函数来设置它:
function simulate_get ($key, $value) {
$_GET[$key] = $value;
}
simulate_get('foo','last_posts');
show_user_posts($user,$bla,$ble);
答案 2 :(得分:1)
只需更改$ _GET的内容,这完全没问题。
$_GET['foo'] = 'last_posts';