この機能を含めることは可能ですか
function Get_All_Wordpress_Menus(){
return get_terms( 'nav_menu', array( 'hide_empty' => true ) );
}
この配列に
array(
'options' => ADD_FUNCTION_HERE,
);
関数を配列に格納する場合は、次のようにします
。
function foo($text = "Bar")
{
echo $text;
}
// Pass the function to the array. Do not use () here.
$array = array(
'func' => "foo" // Reference to function
);
// And call it.
$array['func'](); // Outputs: "Bar"
$array['func']("Foo Bar"); // Outputs: "Foo Bar"
戻り値を渡す必要がある場合は、非常に簡単です (前の例を想定)。
$array['value'] = foo();
関数自体を保存する必要がある場合は、無名関数を使用します
$arr = array(
'options' => function()
{
return get_terms( 'nav_menu', array( 'hide_empty' => true ) );
}
);
その後、次のように呼び出すことができます
$func = $arr['options'];
$func();
http://php.net/manual/en/functions.anonymous.php
PHP 5.3 より前では不可能であったことに注意してください。Closure objects within arrays before PHP 5.3 に記載されている回避策がありますが、
あなたはこれを必要とします ?
function Get_All_Wordpress_Menus(){
return get_terms( 'nav_menu', array( 'hide_empty' => true ) );
}
$arr = array(
'options' => Get_All_Wordpress_Menus(),
);
function Get_All_Wordpress_Menus($call){
$call = get_terms( 'nav_menu', array( 'hide_empty' => true ) );
return $call;
}
$array = array(
'options' => $call,
);
また
$array = array(
'options' => Get_All_Wordpress_Menus($call),
);