0

この機能を含めることは可能ですか

function Get_All_Wordpress_Menus(){
    return get_terms( 'nav_menu', array( 'hide_empty' => true ) ); 
}

この配列に

array(
    'options' => ADD_FUNCTION_HERE,
);
4

4 に答える 4

0

関数を配列に格納する場合は、次のようにします

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();
于 2013-07-24T13:15:47.037 に答える
0

関数自体を保存する必要がある場合は、無名関数を使用します

$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 に記載されている回避策がありますが、

于 2013-07-24T13:16:29.767 に答える
0

あなたはこれを必要とします ?

function Get_All_Wordpress_Menus(){
    return get_terms( 'nav_menu', array( 'hide_empty' => true ) ); 
}

$arr = array(
    'options' => Get_All_Wordpress_Menus(),
);
于 2013-07-24T13:10:36.060 に答える
0
  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),
);
于 2013-07-24T13:23:21.843 に答える