Home > Backend Development > PHP Tutorial > PHP Advanced: Use Arrays to Complete Powerful Functions_PHP Tutorial

PHP Advanced: Use Arrays to Complete Powerful Functions_PHP Tutorial

WBOY
Release: 2016-07-20 11:04:37
Original
942 people have browsed it

The use of arrays in PHP is at least simpler than in C. The concept of arrays is rarely used in general PHP programs. Judgments, loops and cookies are mostly used, but it is very important to master the skills of using arrays. Because it can make the functions of the program more automated, allowing customers to choose between a program with powerful functions but poor operating performance and a program with small and exquisite functions but very convenient operation. I think customers will choose the latter.
Before introducing the use of arrays, I I have to state here that I am just introducing the idea of ​​using arrays, that is, under what circumstances arrays can be used to simplify tasks. The examples given are only to provide an idea and will not cover everything.
When to use arrays? Generally, when encountering large-scale variable transmission and processing, consider using arrays.
An example of how I used arrays to complete tasks:
Once I wrote a background management program for a customer. After the program was completed, The customer was very satisfied, but after a while the customer came to me and said: "I found a lot of junk information in it, and I don't want to keep it. I ran into trouble when deleting it. I had to click every time." 'Delete' to delete every message. Can you help me design a function to delete all junk at once..."; Of course I accepted this task, because the customer is God.
Add this function to the management at the beginning When programming, I considered using an array to complete it, so I wrote a flow chart:
Find the unique identifier id of spam --> Array --> Delete the database record corresponding to the id in the array
Now with this flowchart, we can start designing the program. In order to use the array to successfully transfer variables, I used the checkbox of the submission table. The specific writing method:
echo "";
In this way, I add the spam id to the space corresponding to the array subscript, so that I can perform actual operations on the database. Let's see how the array is passed to How to complete the task when deleting the function block;
//First find the ids of all records in the database:
.....
for ($i=0;$i<$num;$i++) {
$id=mysql_result($result,$i,"id");
//Judge array
if (!empty($delete[$id])) {
//Execute Delete command
mysql_query("delete from table where id=$id");
}
}
......
An automated deletion function is completed, using an array to return It can complete many different tasks such as: randomly updating pictures, comparison, etc...
Using arrays can complete some seemingly difficult tasks

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445182.htmlTechArticleThe use of arrays in PHP is at least simpler than in C. Arrays are rarely used in general PHP programs. This concept is mostly used in judgment, looping and cookies, but mastering the skills of using arrays...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template