我有一个像这样的简单链接:<a href="?wp_accept_function=10">Accept</a>
想法是这将运行一个名为 wp_accept_function 的函数并传入 10 的 ID 我该怎么做?谢谢
这是我目前的代码,但我觉得我做错了,需要将数字传递到函数中,然后才能在函数中使用它。谢谢
if ( isset ( $_GET ['wp_accept_function'] ) )
{
function wp_accept_favor ( $id )
{
// JAZZ
}
}
最佳答案
我想你想要这个:
首先您需要定义函数。
function wp_accept_favor($id) {
// do something
}
然后,您必须检查参数是否已设置并调用函数。
if (isset($_GET['wp_accept_function'])) {
// call the function passing the id casted to an integer
wp_accept_favor((int)$_GET['wp_accept_function']);
}
转换为 (int)
是为了避免为 wp_accept_favor()
函数传递非整数类型,但您可以根据需要进行处理。
关于php - 如何调用 GET 参数中指定的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4893344/