Wrote a function _php tutorial

Source: Internet
Author: User
/**
* Function Data_box
* Function outputs the contents of the data source according to the template
* Parameters
* $fun callback function, must be provided. The function is to read data from the data source. It is best to return an associative array
* $source data source, must be provided. can be an array or query result
* $template template, can not. Output data with standard tables when no template is provided
* Template format:
* Array (top=> "",block=> "",fool=> "")
which
* Top Start section
* Block repeatable part, variable is an associative array of keys, shaped like $in_varname. Where the leading in_ can be omitted
* Fool End part
*/
function Data_box ($_fun,$_source,$_template= "") {
$_ar = $_fun (&$_source);
if ($_template = = "") {
while (list ($k,) = each ($_ar)) {
$th. = "$k";
$td. = "$IN _$k";
}
$_template = Array (top=> "$th",block=> "$TD",fool=> "
");
}else if (! Preg_match ("/$IN _w+/", $_template[block]))
$_template[block] = preg_replace ("/[$" (w*)/U "," $IN _1 ", $_template[block]);
$buf = eval ("Return" $_template[top] ";");
do {
Extract ($_ar, Extr_prefix_all, "in");
$buf. = eval ("Return" $_template[block] ";");
}while ($_ar = $_fun (&$_source));
$buf. = eval ("Return" $_template[fool] ";");
return $buf;
}
function Get_data ($source) {
if (list ($k, $v) = each ($source))
return $v;
return false;
}
$arr = Array (
Array (a=>1,b=>2,c=>3,11,12,31),
Array (a=>11,b=>12,c=>13,11,12,131)
);
Echo Data_box ("Get_data", $arr);
Echo Data_box ("Get_data", $arr, Array (top=> "list test ",block=> '$b ',fool=> '
"));

http://www.bkjia.com/PHPjc/445594.html www.bkjia.com true http://www.bkjia.com/PHPjc/445594.html techarticle /** * Function Data_box * Function According to the template output the contents of the data source * parameters * $fun callback function, must be provided. The function is to read data from the data source. The best way to ask for a return is to close ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.