A function is written.

Source: Internet
Author: User

  /**
* 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 =>"
"));

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.