/**
* 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 ...