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

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 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months 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)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

See all articles