Home Backend Development PHP Tutorial About PHP recursive array code analysis_PHP tutorial

About PHP recursive array code analysis_PHP tutorial

Jul 15, 2016 pm 01:28 PM
a html php and code about analyze Microsoft us array yes of Know language recursion

We all know that PHP is an HTML embedded language. PHP is quite similar to Microsoft's ASP. They are both scripting languages ​​that are executed on the server side and embedded in HTML documents. The language The style is similar to C language and is now widely used by many website programmers. This article introduces PHP recursive arrays in detail. The PHP program needs to write the received data to both the "formal database for online operation" and the "test database for development and debugging".

The test database may often face problems such as adjusting the table structure, fields, and configuration information. It is very unstable and has a high probability of errors. If Using the a.php program to write the "formal database" and "test database" at the same time will inevitably affect the formal services running online. So, I thought of using the PHP curl extension library to post a copy of the generated $data array to the PHP program, and then the PHP program continued to execute the code to write the "formal database". The PHP program passes the $data array to the PHP program and that's it. As for how PHP handles it, it has nothing to do with PHP. Even if the PHP program fails to write the "test database", it will not have an impact on the PHP program.

PHP recursive array source code:

<ol class="dp-xml">
<li class="alt">
<span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN> </SPAN></SPAN><LI class=""><SPAN>$data["username"]="张宴";  </SPAN><LI class=alt><SPAN>$data["password"]="不知道";  </SPAN><LI class=""><SPAN>$data["ip"]="192.168.0.18";  </SPAN><LI class=alt><SPAN>//reGISter_shutdown_function("post_data", $data);  </SPAN><LI class=""><SPAN>//function post_data($data)  </SPAN><LI class=alt><SPAN>//{  </SPAN><LI class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>curl</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>new</FONT></SPAN><SPAN> Curl_Class();  </SPAN></SPAN><LI class=alt><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>post</FONT></SPAN><SPAN> = @$curl-</SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong></span><span>post("http://127.0.0.1/b.php", $data);//这里是b.php的访问地址,请自行修改  </span>
</li>
<li class=""><span>//}  </span></li>
<li class="alt"><span>//curl类  </span></li>
<li class=""><span>class Curl_Class  </span></li>
<li class="alt"><span>{  </span></li>
<li class=""><span>function Curl_Class()  </span></li>
<li class="alt"><span>{  </span></li>
<li class=""><span>return true;  </span></li>
<li class="alt"><span>}  </span></li>
<li class="">
<span>function execute($method, $url, $</span><span class="attribute"><font color="#ff0000">fields</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">''</font></span><span>, $</span><span class="attribute"><font color="#ff0000">userAgent</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">''</font></span><span>, $</span><span class="attribute"><font color="#ff0000">httpHeaders</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">''</font></span><span>, $</span><span class="attribute"><font color="#ff0000">username</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">''</font></span><span>, $</span><span class="attribute"><font color="#ff0000">password</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">''</font></span><span>)  </span>
</li>
<li class="alt"><span>{  </span></li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">ch</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">Curl_Class</font></span><span>::create();  </span>
</li>
<li class="alt">
<span>if (</span><span class="attribute"><font color="#ff0000">false</font></span><span> === $ch)  </span>
</li>
<li class=""><span>{  </span></li>
<li class="alt"><span>return false;  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span>if (is_string($url) && strlen($url))  </span></li>
<li class=""><span>{  </span></li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">ret</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">curl_setopt</font></span><span>($ch, CURLOPT_URL, $url);  </span>
</li>
<li class=""><span>}  </span></li>
<li class="alt"><span>else  </span></li>
<li class=""><span>{  </span></li>
<li class="alt"><span>return false;  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span>//是否显示头部信息  </span></li>
<li class=""><span>curl_setopt($ch, CURLOPT_HEADER, false);  </span></li>
<li class="alt"><span>//  </span></li>
<li class=""><span>curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  </span></li>
<li class="alt"><span>if ($username != '')  </span></li>
<li class=""><span>{  </span></li>
<li class="alt"><span>curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);  </span></li>
<li class=""><span>}  </span></li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">method</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">strtolower</font></span><span>($method);  </span>
</li>
<li class=""><span>if ('post' == $method)  </span></li>
<li class="alt"><span>{  </span></li>
<li class=""><span>curl_setopt($ch, CURLOPT_POST, true);  </span></li>
<li class="alt"><span>if (is_array($fields))  </span></li>
<li class=""><span>{  </span></li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">sets</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">array</font></span><span>();  </span>
</li>
<li class="">
<span>foreach ($fields AS $</span><span class="attribute"><font color="#ff0000">key</font></span><span> =</span><span class="tag"><strong><font color="#006699">></font></strong></span><span> $val)  </span>
</li>
<li class="alt"><span>{  </span></li>
<li class=""><span>$sets[] = $key . '=' . urlencode($val);  </span></li>
<li class="alt"><span>}  </span></li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">fields</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">implode</font></span><span>('&',$sets);  </span>
</li>
<li class="alt"><span>}  </span></li>
<li class=""><span>curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span>else if ('put' == $method)  </span></li>
<li class="alt"><span>{  </span></li>
<li class=""><span>curl_setopt($ch, CURLOPT_PUT, true);  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span>//curl_setopt($ch, CURLOPT_PROGRESS, true);  </span></li>
<li class="alt"><span>//curl_setopt($ch, CURLOPT_VERBOSE, true);  </span></li>
<li class=""><span>//curl_setopt($ch, CURLOPT_MUTE, false);  </span></li>
<li class="alt"><span>curl_setopt($ch, CURLOPT_TIMEOUT, 3);//设置curl超时秒数,例如将信息POST出去3秒钟后自动结束运行。  </span></li>
<li class=""><span>if (strlen($userAgent))  </span></li>
<li class="alt"><span>{  </span></li>
<li class=""><span>curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span>if (is_array($httpHeaders))  </span></li>
<li class="alt"><span>{  </span></li>
<li class=""><span>curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);  </span></li>
<li class="alt"><span>}  </span></li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">ret</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">curl_exec</font></span><span>($ch);  </span>
</li>
<li class="alt"><span>if (curl_errno($ch))  </span></li>
<li class=""><span>{  </span></li>
<li class="alt"><span>curl_close($ch);  </span></li>
<li class=""><span>return array(curl_error($ch), curl_errno($ch));  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span>else  </span></li>
<li class="alt"><span>{  </span></li>
<li class=""><span>curl_close($ch);  </span></li>
<li class="alt"><span>if (!is_string($ret) || !strlen($ret))  </span></li>
<li class=""><span>{  </span></li>
<li class="alt"><span>return false;  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span>return $ret;  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span>}  </span></li>
<li class="">
<span>function post($url, $fields, $</span><span class="attribute"><font color="#ff0000">userAgent</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">''</font></span><span>, $</span><span class="attribute"><font color="#ff0000">httpHeaders</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">''</font></span><span>, $</span><span class="attribute"><font color="#ff0000">username</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">''</font></span><span>, $</span><span class="attribute"><font color="#ff0000">password</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">''</font></span><span>)  </span>
</li>
<li class="alt"><span>{  </span></li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">ret</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">Curl_Class</font></span><span>::execute('POST', $url, $fields, $userAgent, $httpHeaders, $username, $password);  </span>
</li>
<li class="alt">
<span>if (</span><span class="attribute"><font color="#ff0000">false</font></span><span> === $ret)  </span>
</li>
<li class=""><span>{  </span></li>
<li class="alt"><span>return false;  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span>if (is_array($ret))  </span></li>
<li class=""><span>{  </span></li>
<li class="alt"><span>return false;  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span>return $ret;  </span></li>
<li class=""><span>}  </span></li>
<li class="alt">
<span>function get($url, $</span><span class="attribute"><font color="#ff0000">userAgent</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">''</font></span><span>, $</span><span class="attribute"><font color="#ff0000">httpHeaders</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">''</font></span><span>, $</span><span class="attribute"><font color="#ff0000">username</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">''</font></span><span>, $</span><span class="attribute"><font color="#ff0000">password</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">''</font></span><span>)  </span>
</li>
<li class=""><span>{  </span></li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">ret</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">Curl_Class</font></span><span>::execute('GET', $url, '', $userAgent, $httpHeaders, $username, $password);  </span>
</li>
<li class="">
<span>if (</span><span class="attribute"><font color="#ff0000">false</font></span><span> === $ret)  </span>
</li>
<li class="alt"><span>{  </span></li>
<li class=""><span>return false;  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span>if (is_array($ret))  </span></li>
<li class="alt"><span>{  </span></li>
<li class=""><span>return false;  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span>return $ret;  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span>function create()  </span></li>
<li class="alt"><span>{  </span></li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">ch</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">null</font></span><span>;  </span>
</li>
<li class="alt"><span>if (!function_exists('curl_init'))  </span></li>
<li class=""><span>{  </span></li>
<li class="alt"><span>return false;  </span></li>
<li class=""><span>}  </span></li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">ch</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">curl_init</font></span><span>();  </span>
</li>
<li class=""><span>if (!is_resource($ch))  </span></li>
<li class="alt"><span>{  </span></li>
<li class=""><span>return false;  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span>return $ch;  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span>}  </span></li>
<li class="alt">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span>
</li>
</ol>
Copy after login

PHP recursive array code:

<ol class="dp-xml">
<li class="alt">
<span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN>    </SPAN></SPAN><LI class=""><SPAN>ignore_user_abort();//连线中断后(例如关闭浏览器)仍然继续执行以下的脚本直到处理完毕。  </SPAN><LI class=alt><SPAN>set_time_limit(0);  </SPAN><LI class=""><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>get_data</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>file_get_contents</FONT></SPAN><SPAN>("php://input");  </SPAN></SPAN><LI class=alt><SPAN>$</SPAN><SPAN class=attribute-value><FONT color=#0000ff>explode</FONT></SPAN><SPAN class=attribute><FONT color=#ff0000>explodedata</FONT></SPAN><SPAN> = explode("&", $get_data);  </SPAN></SPAN><LI class=""><SPAN>foreach ($explodedata as $</SPAN><SPAN class=attribute><FONT color=#ff0000>key</FONT></SPAN><SPAN> =</SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong></span><span> $value)//还原数组  </span>
</li>
<li class="alt"><span>{  </span></li>
<li class=""><span>list($realkey, $realvalue) = explode("=", $value);  </span></li>
<li class="alt"><span>$data[urldecode($realkey)] = urldecode($realvalue);  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span>//现在$data数组已经和a.php中的一样了,接下来,就可以根据自己的需要对$data数组进行操作了。  </span></li>
<li class=""><span>//......  </span></li>
<li class="alt">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span>
</li>
</ol>
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446465.htmlTechArticleWe all know that PHP is an HTML embedded language. PHP is quite similar to Microsoft's ASP. Similar, they are both scripting languages ​​embedded in HTML documents that are executed on the server side. The style of the language...
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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 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)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

HTML: The Structure, CSS: The Style, JavaScript: The Behavior HTML: The Structure, CSS: The Style, JavaScript: The Behavior Apr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

See all articles