Php advanced: use arrays to complete powerful functions
Source: Internet
Author: User
Php advanced: Using arrays to accomplish powerful functions arrays is at least easier to use in php than using arrays in C. The concept of arrays is rarely used in common php programs, it uses mostly judgment, loop, and cookie, but it is very important to master the array usage skills, because it can make the functions of the program more automated, let the customer select in a program with powerful functions but poor operation performance and small functions but easy to operate. I think the customer will select the latter.
Before introducing array application, I have to declare here that I am only introducing the idea of using arrays, that is, under what circumstances can I use arrays to simplify the task, the example only provides an idea and does not cover all aspects.
When to use arrays, we usually consider using arrays to transfer and process a large range of variables.
I use an array to complete the task:
Once I wrote a background management program for the customer. after the program was completed, the customer was very satisfied, but soon the customer came to me and said to me: "I found a lot of junk information in it and I didn't want to keep it. I was in trouble when I deleted it, I have to click 'delete' each time to delete each piece of information. can you help me design a function to delete all junk files... "; of course I accept this task because the customer is God.
When I started to add this function to the management program, I considered using arrays to complete it, so I wrote a flowchart:
Find the unique identification word id of junk information --> array --> the id in the corresponding array to delete database records
Now we can design the program by using this flowchart. to use the array to successfully pass variables, I used the checkbox for submitting the table block. the specific statement is as follows:
Echo" ";
In this way, I will attach the id of the junk information to the space corresponding to the array subscript, so that I can perform substantive operations on the database, next let's take a look at how the task is completed when the array is uploaded to the delete function block;
// First, find the IDs of all records in the database:
.....
For ($ I = 0; $ I <$ num; $ I ++ ){
$ Id = mysql_result ($ result, $ I, "id ");
// Determine the array
If (! Empty ($ delete [$ id]) {
// Execute the Delete Command
Mysql_query ("delete from table where id = $ id ");
}
}
......
An automated deletion function is complete. arrays can also be used to complete many different tasks, such as random image update and comparison...
Using arrays to complete some seemingly difficult tasks
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.