[Happy Learning php100 Day] The next day: Crazy array _php Tutorial

Source: Internet
Author: User
Tags echo date learn php php foreach
Previous link: happy to learn php100 day the first day of the motto: Why some people learn PHP always feel that some knowledge point learning is very good knowledge point but always learn not, that is because the face of the study when the muscles too tense, resulting in nerve endings necrosis, so lame. This issue: The PHP array is the most iconic tool feature in PHP. Learn PHP arrays Basically you have the initial capital mixed up in the PHP world. I used to have a friend run a computer company. General Computer Company's main business is to sell computers, occasionally will take some spare parts, of course, depending on the situation there are some companies with the sale of some CDs, such as movies, games and so on. My friend is more technical. He is also a grassroots programmer, the sale of CD-ROM behavior is very despised, especially the CD-ROM to sell the island. At the beginning of a long period of time his main business is to help some companies or companies to do website. At that time, the propaganda site is completely not complex now, basically 2-3 pages, dynamic site more than 10 interface, and there is a lot of free space at that time, so he that hundreds of hundreds of earn very easy, very agile, very efficient ah, I have "steal teacher" his website code, I do not remember clearly all, Can only yy a bit about the appearance, we can underestimate, PHP: [php] View plaincopy <title><?php Echo $fix [0]?></title>


//Note that 800*600 was the national standard at the time, do not think too much ?
.... Here is a mess of impracticality God ....
.... This is the same kind of Web site support each other interspersed ads, such as: "Arouse your Heart of the Tiger" or "use xxx after the legs good, also do not urinate" and so on.
!--? php foreach ($var as $eachline) echo '
  • '. $eachline. '
  • ';
    //The product title is scariness, meaning that you will regret the trip to the world without buying?>
    ... Note that this is already the end of the page ...//Note that the filing was really lax!--? php echo $fix [2]. $fix [3]?-->!--? php echo date (& #39; y-m-d h:i:s&# 39;);? -->//Note at that time my friend could not script, so the page would have to be brushed once to change the current time.
    Well, that's one of the basic skills that my friends rely on to survive. It is said to change the same type of customer he just put "product list. txt" exchange for content, and then the TD background picture replaced, the page immediately wash new leather noodles, my friend was very serious at that time told me that he has achieved "product" development model. I worship the pleasantly surprised, because I was a beginner ASP, there is absolutely no such "configurable." Pages inside the ads and statements do not too tangled, anyway, at that time as a small white I read this page, I would like to spend money to try, but my friend told me that I did not use the time. I asked "When can I use", My friend "fan" me a slap. Next, let's cut to the chase and explain the knowledge points above. First, the most basic expression of the array $fix =array ("Content 1", "Content 2", "Content 3"); This is the basic representation of the PHP array. Please forgive me for not wanting to repeat the advertising words again, it's disgusting. You want to pile up as much content as you can, as long as you write it down. When you want to invoke the content inside, you simply call from "0" to start counting, such as $fix[0], $fix [1] ... $fix [n]. Note: Why start from 0. One is because "PHP boss" is so designed, the other is because the most basic array of the =array is $fix (0=> "Content 1",1=> "Content 2",2=> "Content 3"); "= =" This symbol is omitted, the symbol to the left is the key, the right is a value, in general, many textbooks will be interpreted as "$key and $value". Let's not tangle why the left is $key to the right is $value, I tell everyone is the customary wording, you have to write $ss > $bb, the one on the left is the key, and the one on the right is the value. Therefore, any form of an array will have keys and values. The province does not omit to look at you, whether you save the province, anyway, I saved. Expand: Since there is a key value, you can change the key value. For example $fix =array ("exaggerated website name" and "China's biggest XXX website", "RIP egg product brand" = "Only we are the most authentic", "listen to want to vomit advertising language" = "false a penalty ten never deceptive"); This time if you want to export the "RIP product brand" to the page, you can't use echo $fix [1]; Because the key value has been changed by you. Should use Echo to $fix [' RIP the Product brand ']; Second, the traversal array continues to $fix =array ("Content 1", "Content 2", "Content 3"); For example 1, using foreach is the most suitable method for looping a small array. The basic syntax is: foreach (here is the original array as this writes the variable that is set at each traversalFor example: The Echo $eachline of the foreach ($var as $eachline); This will output the content 1 .... Content 3; 2, a lot of people know there is actually a while can iterate the array basic syntax is: while (List ($key, $value) =each ($attr)) For example: while (List ($key, $value) =each ($fix)) echo $key. $value; The 0 contents of 1 ... will be output sequentially. 2 content 2; The two traversal differences are not too deep here, and later, I'm just telling you, if you're just going to traverse the data, use foreach whenever you want. If you want to change the value of the array during traversal, use while. The reason is only one word, for "fast". Now the pace of life is too fast, the first principle of writing procedures is "fast." As for the other syntax to iterate over an array, I personally think that we do not have to learn, unless you go to test the scholar, if the actual combat these two kinds of enough, we also for the fast. Expand, the value of the array can not only put a string, you can also put an array can also be any form of variable values. such as $fix =array ("the slogan" =>array ("The Top 100 subscribers, then send 200 yuan package", "20 days proficient in a language", "children do not eat because of lack of x")); For such an array, the value of the $fix [' RIP ad word '] is actually a number of groups, such as Echo $fix ['][1 ' of the advertising word]; Will output "20 days proficient in a language" three, the assignment of the array to give an example: $fix =array (); This array is empty. $fix []= "Content 1"; This is equivalent to $fix =array ("Content 1") or $fix=array (0=> "Content 1"); $fix []= "Content 2"; This is equivalent to $fix =array ("Content 1", "Content 2"); or $fix =array (0=> "Content 1",1=> "Content 2"); $fix [' What we're learning ']= ' php '; This is equivalent to $fix =array (0=> "Content 1", "What we are learning" = "php"); The above assignment is in the end of the array assignment, in fact, there are array_push functions can be assigned, the syntax is $fix=array_push ($fix, "Content 1", "Content 2"), the effect is the same, but Array_push can add a lot of value, with ' [] ' One at a time. PHP array functions are powerful and can do almost anything, such as array sorting, merging, reversing,Delete and so on, we can Baidu a bit, due to the length of the problem here not much, function backrest, rely on more use will, not difficult. However, to the actual combat to do the project a lot of data processing needs through the database stored procedures, optimized table structure, good data sorting algorithm, the technique of data read way to do, the actual actual combat PHP inside a good majority of the functions of the group is basically not used, for example, you received a 1230X such a project, To list all the Chinese names and sort you dare to use the PHP array to traverse the stem and merge and invert. Of course, if your client is facing the Vatican or Iceland, you can do that. However, many functions, such as whether is_array--is an array in_array---whether there is a value, array_key_exists---the existence of a key value in the array, and so on the commonly used functions must be learned. If you do not learn, then you are not far from being a leader. Easter Egg: There is a $var =file ("./Product list. txt") above; This means that the text document is read one time and the array is read by line, including newline characters.

    http://www.bkjia.com/PHPjc/477566.html www.bkjia.com true http://www.bkjia.com/PHPjc/477566.html techarticle Previous link: happy to learn php100 day the first day of the motto: Why some people learn PHP always feel that some knowledge point learning is very good knowledge point but always learn not, it is because the face of learning ...

  • Contact Us

    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

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.