Home Backend Development PHP Tutorial Wrote a function_PHP tutorial

Wrote a function_PHP tutorial

Jul 20, 2016 am 10:59 AM
box data indivual content function Function parameter callback supply data source template output

  /**
* Function data_box
* Function: Output the content in the data source according to the template
* Parameter
* $fun callback function, must be provided. Its function is to read data from the data source. The best thing to return is an associative array
* $source data source, must be provided. Can be an array or query result
* $template template, optional. Use standard tables to output data when no template is provided
* Template format:
* array(top=>"",block=>"",fool=>"")
* Among them:
* top beginning part
* The repeatable part of block, the variable is the key of the associative array, in the form of $IN_varname. The leading IN_ can be omitted
* end of fool
*/
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=>"列表测试
"));

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445594.htmlTechArticle/** * 函数 data_box * 功能 根据模板输出数据源中的内容 * 参数 * $fun 回调函数,必须提供。作用是从数据源中读取数据。要求返回的最好是关...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Tips for dynamically creating new functions in golang functions Tips for dynamically creating new functions in golang functions Apr 25, 2024 pm 02:39 PM

Go language provides two dynamic function creation technologies: closure and reflection. closures allow access to variables within the closure scope, and reflection can create new functions using the FuncOf function. These technologies are useful in customizing HTTP routers, implementing highly customizable systems, and building pluggable components.

Considerations for parameter order in C++ function naming Considerations for parameter order in C++ function naming Apr 24, 2024 pm 04:21 PM

In C++ function naming, it is crucial to consider parameter order to improve readability, reduce errors, and facilitate refactoring. Common parameter order conventions include: action-object, object-action, semantic meaning, and standard library compliance. The optimal order depends on the purpose of the function, parameter types, potential confusion, and language conventions.

How to write efficient and maintainable functions in Java? How to write efficient and maintainable functions in Java? Apr 24, 2024 am 11:33 AM

The key to writing efficient and maintainable Java functions is: keep it simple. Use meaningful naming. Handle special situations. Use appropriate visibility.

Complete collection of excel function formulas Complete collection of excel function formulas May 07, 2024 pm 12:04 PM

1. The SUM function is used to sum the numbers in a column or a group of cells, for example: =SUM(A1:J10). 2. The AVERAGE function is used to calculate the average of the numbers in a column or a group of cells, for example: =AVERAGE(A1:A10). 3. COUNT function, used to count the number of numbers or text in a column or a group of cells, for example: =COUNT(A1:A10) 4. IF function, used to make logical judgments based on specified conditions and return the corresponding result.

What is GateToken(GT) currency? Introduction to GT coin functions and token economics What is GateToken(GT) currency? Introduction to GT coin functions and token economics Jul 15, 2024 pm 04:36 PM

What is GateToken(GT) currency? GT (GateToken) is the native asset on the GateChain chain and the official platform currency of Gate.io. The value of GT coins is closely related to the development of Gate.io and GateChain ecology. What is GateChain? GateChain was born in 2018 and is a new generation of high-performance public chain launched by Gate.io. GateChain focuses on protecting the security of users' on-chain assets and providing convenient decentralized transaction services. GateChain's goal is to build an enterprise-level secure and efficient decentralized digital asset storage, distribution and transaction ecosystem. Gatechain has original

C++ Function Exception Advanced: Customized Error Handling C++ Function Exception Advanced: Customized Error Handling May 01, 2024 pm 06:39 PM

Exception handling in C++ can be enhanced through custom exception classes that provide specific error messages, contextual information, and perform custom actions based on the error type. Define an exception class inherited from std::exception to provide specific error information. Use the throw keyword to throw a custom exception. Use dynamic_cast in a try-catch block to convert the caught exception to a custom exception type. In the actual case, the open_file function throws a FileNotFoundException exception. Catching and handling the exception can provide a more specific error message.

Things to note when Golang functions receive map parameters Things to note when Golang functions receive map parameters Jun 04, 2024 am 10:31 AM

When passing a map to a function in Go, a copy will be created by default, and modifications to the copy will not affect the original map. If you need to modify the original map, you can pass it through a pointer. Empty maps need to be handled with care, because they are technically nil pointers, and passing an empty map to a function that expects a non-empty map will cause an error.

Comparison of C++ templates and generics? Comparison of C++ templates and generics? Jun 04, 2024 pm 04:24 PM

The difference between templates and generics in C++: Templates: defined at compile time, clearly typed, high efficiency, and small code size. Generics: runtime typing, abstract interface, provides flexibility, low efficiency.

See all articles