Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 函数作为函数输入_Php_Function - Fatal编程技术网

Php 函数作为函数输入

Php 函数作为函数输入,php,function,Php,Function,我想创建自己的模板来构建下一个web项目 但我的问题是,我正试图用我自己的函数创建我自己的模板系统,同时也在学习更多关于我的代码的知识 我正在努力改进我的代码,使我在编写代码时变得干净/流畅 但现在我遇到了这个问题 a-function-file.php <?php $Website_info = array("SiteTitle"=>"CLiCK", "BaseUrl"=>"http://localhost/CLick/"); //css styles her $w

我想创建自己的模板来构建下一个web项目

但我的问题是,我正试图用我自己的函数创建我自己的模板系统,同时也在学习更多关于我的代码的知识

我正在努力改进我的代码,使我在编写代码时变得干净/流畅

但现在我遇到了这个问题

a-function-file.php

<?php    
$Website_info = array("SiteTitle"=>"CLiCK", "BaseUrl"=>"http://localhost/CLick/");

//css styles her
$website_styles = array(
array("src"=>"libs/css/bootstrap.min.css", "type"=>"text/css"),
array("src"=>"libs/themes/click.css", "type"=>"text/css")
);

//javascripts her
$website_scripts = array(
array("src"=>"libs/js/bootstrap.min.js", "type"=>"text/javascript")
);


$website_navigation_top_links = array(
array("link"=>"index.php","name"=>"Home")
);


function Click_styles()
{
    global $website_styles;
    $styleOutput = "";
    foreach ($website_styles as $key => $CssStyle):
    $styleOutput .=  "<link href='".$CssStyle["src"]."' rel='stylesheet' type='".$CssStyle["type"]."'>\n";
    endforeach;
    return $styleOutput;
}

//my function to create html codes within head tags
function Click_header() 
{
    //Getting website info into function
    global $Website_info;
    global $website_styles;
    $ImpotedStyles = Click_styles();    
    //creating the html (can maybe be created more clean later)
    $Header_output = "<title>".$Website_info["SiteTitle"]."</title>\n";
    $Header_output .= "<base href='".$Website_info["BaseUrl"]."' />\n";
    $Header_output = $Header_output.$ImpotedStyles;
    // return the complied output (as HTML)
    return $Header_output;
}

?>

我自己找到了这个解决方案

<?php
function printHTML($CustomFunction,$Description="")
{
 $function = ($CustomFunction;
    echo $function();
}
?>

我自己发明了这个解决方案
code
<?php 
//the function that doesnt work
function printHTML($ThisShouldBeAFunctionNotAVar, $Description="none") {
    echo $ThisShouldBeAFunctionNotAVar
}
?>


<?php
//how I want to use the function
printHTML(Click_header(), "The website header");
//and maybe if I had a footer I could display the return of that function too
printHTML(Click_foter(), "a smart footer function");
?>
<?php
function printHTML($CustomFunction,$Description="")
{
 $function = ($CustomFunction;
    echo $function();
}
?>