我试图创建什么,如果可能的话,在WordPress或通过php是,我有如下的功能。
function myfunction_displays_something_one() {
echo "string";
echo "string"; }
function myfunction_displays_something_two() {
echo "string";
echo "string";
}
function myfunction_displays_something_three( $arg1, $arg2 ) {
echo "<p>";
echo $arg1 $arg2;
echo "/<p>";
}我希望通过调用和显示上面的函数
function myfunction_displays( $display ) {
if ( $display == 'something-one' )
return myfunction_displays_something_two();
if ( $display == 'soemthing-two' )
return myfunction_displays_something_two();
}当调用vai时,php文件希望调用上面的三个函数,如下所示
<?php myfunction_displays( something-two ); ?>
<?php myfunction_displays( something-three ); ?>我能够使前两个函数工作,因为它们没有参数,但我无法调用第三个函数,因为它有参数。
有没有办法创建它,比如使用Wordpress过滤器或者只使用php?
发布于 2014-01-09 02:52:57
function myfunction_displays( $display ,$arrArg = array()) {
if ( $display == 'something-one' )
return myfunction_displays_something_two();
if ( $display == 'soemthing-two' )
return myfunction_displays_something_two();
if ( $display == 'soemthing-three' )
{
$a1 = isset($arrArg[0]) ? $arrArg[0] : "";
$a2 = isset($arrArg[1]) ? $arrArg[1] : "";
return myfunction_displays_something_three($a1,$a2);
}
}然后这样叫它:
<?php myfunction_displays( 'something-two' ); ?>
<?php myfunction_displays( 'something-three',array(0=>'value1',1=>'value2')); ?>发布于 2014-01-09 02:55:12
这里有一个快速的方法:
function myfunction_displays( $display, $arg1=NULL, $arg2=NULL ) {
if ( $display == 'something-one' )
return myfunction_displays_something_two();
if ( $display == 'something-two' )
return myfunction_displays_something_two();
if ( $display == 'something-three' )
return myfunction_displays_something_three($arg1, $arg2);
}"=NULL“部分意味着您不必在每次调用它时都填充它们。
举个例子:
<?php myfunction_displays( 'something-two' ); ?>
<?php myfunction_displays( 'something-three', 'value1', 'value2' ); ?>https://stackoverflow.com/questions/21004043
复制相似问题