PHP Advanced: The ability to perform powerful functions by utilizing arrays
Source: Internet
Author: User
The use of arrays in PHP is at least as simple as C, in the general PHP program is rarely used in the concept of the array, with more of the judgment, loop and cookies, but the use of the array of skills is very important, because it can make the function of the program more automation, To allow customers to choose from programs that are powerful but with poor operating performance and a very convenient operation, I think the customer will choose the latter.
Before I introduce the array, I have to say here that I'm just introducing the idea of using arrays, in which case an array can be used to simplify the task, and the example provided is simply a way of thinking and not exhaustive.
When an array is used, it is generally considered to be done with an array when a large range of variable transfer and processing is encountered.
I use an array to complete an instance of a task:
Once I wrote a background management program for my client, after the program was completed, the customer was satisfied, but soon after the client came to me, and said to me: "I found that there are a lot of junk information, I do not want to keep them, in the deletion, I encountered trouble, I have to point to ' delete ' To delete every piece of information. Can you help me design one time to remove all the junk ... "; Of course I accepted the task, because the client is God.
When I started adding this feature to the Admin program, I thought about using an array to do it, so I wrote a flowchart:
Find spam unique identifier ID--> array--> the ID of the corresponding array delete database records
Well, from this flowchart, you can begin to design the program, in order to use the array to successfully transfer variables, I used the file to submit the checkbox, the specific wording:
echo "<input type=checkbox name=delete[$id] value= ' y ' >";
So I will be the ID of the garbage and the array of the corresponding space attached value, so that the database can be a real operation, the following to see how the array is passed to delete the function block is how to complete the task;
First look up the IDs for all the records in the database:
.....
for ($i =0; $i < $num; $i + +) {
$id =mysql_result ($result, $i, "id");
Judging arrays
if (!empty ($delete [$id])) {
Execute Delete command
mysql_query ("Delete from table where id= $id");
}
}
......
An automated deletion function is complete, with an array can also accomplish many different tasks such as: Random update pictures, contrast and so on ...
A flexible array can do something that looks hard to do
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service