[英]PHP function variable from variable
我有一个这样的PHP函数:
// Return the thread ID.
return $message->thread_id;
我不需要为以下任何其他内容返回thread_id。 然后我将如何调用具有以下参数的函数:
function messages_delete_thread( $thread_ids, $user_id = 0 )
我努力了
// return $message->thread_id; (commented out as I don't need to 'return' I just want to get this value for the next line)
messages_delete_thread(thread_id,bp_loggedin_user_id());
但这没有用,因为return
有效地结束了函数-我该怎么办呢?
作为参考, bp_loggedin_user_id()
应该正在获取当前用户。 我正在从这里使用messages_new_message和messages_delete_thread
假设您的第一个函数的名称为example
:
function example(){
// some code
return $message->thread_id;
}
要实现您想做的事情,您必须将返回的结果存储到变量中,或者直接将其作为第二个函数的参数来调用。
$threadId = example();
messages_delete_thread($threadId, bp_loggedin_user_id());
要么
messages_delete_thread(example(), bp_loggedin_user_id());
您只需将第一个函数的结果分配给一个变量,然后将该变量传递给第二个函数的调用。
function firstFunction()
{
// ... whatever the code is
// Return the thread ID.
return $message->thread_id;
}
$threadId = firstFunction();
messages_delete_thread($threadId,bp_loggedin_user_id());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.