/**
* Function data_box
* Outputs the content of the data source based on the template.
* Parameters
* $ Fun callback function, required. The function is to read data from the data source. It is best to associate the returned array
* $ Source data source, which must be provided. It can be an array or query result.
* $ Template, which may not exist. Use a standard table to output data when no template is provided
* Template format:
* Array (top => "", block => "", fool => "")
* Where:
* Top start part
* The block can be repeated. The variable is the key of the associated array, for example, $ IN_varname. 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 =>"
"));