How to use PHP associative arrays _php Tutorial

Source: Internet
Author: User
When we operate the database, we need to use theLet's look at an array traversal of a basic number format:

 
  
  
  1. Php
  2. $temp [0] = "Richmond";
  3. $temp [1] = "tigers";
  4. $temp [2] = "premiers";
  5. For ($x=0; $x<Count ($temp); $x + + )
  6. {
  7. echo $temp [$x];
  8. echo "";
  9. }
  10. ?>

Another way to save more code, however, is:

 
  
  
  1. Php
  2. $ Temp Array("Richmond", "tigers", "premiers");
  3. foreach ($temp as $element)
  4. echo "$element";
  5. ?>

foreach can also output text subscript:

 
 
    1. !--? php
    2. $ temp = array ("club" = ; " Richmond ",
    3. " nickname "= ; "Tigers",
    4. "aim" = ; "premiers");
    5. foreach ($temp as $ key = ; $value)
    6. echo "$key: $value";
    7. "

This is the relevant use of the PHP associative array in the database.


http://www.bkjia.com/PHPjc/446373.html www.bkjia.com true http://www.bkjia.com/PHPjc/446373.html techarticle when we operate the database, we need to use the following we look at a basic number format array traversal: PHP $temp [0]= "Richmond", $temp [1]= "tigers"; $temp [2]= "premiers"; for ...

  • Related Article

    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.