Results 1 to 5 of 5

Thread: [RESOLVED] What does "=>" do ?

  1. #1

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Resolved [RESOLVED] What does "=>" do ?

    I have seen this line:
    Code:
    foreach($result as $key=>$val)
    I know that, to access a Class object's datamembers or methods, we would be using "->" . But what does this "=>" means ?

    Thanks

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  2. #2
    Hyperactive Member Aash's Avatar
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    491

    Re: What does "=>" do ?

    isn't it a separator used in associative arrays?
    i find so, after google it.
    i mean:
    Code:
    <?php
    $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34); 
    foreach($ages as $key=>$val)
    {
    	echo $key;
    }
    ?>
    Last edited by Aash; Oct 19th, 2011 at 06:59 AM.

  3. #3

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: What does "=>" do ?

    Thanks


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: [RESOLVED] What does "=>" do ?

    It's not specifically used for associative arrays, but simply for describing a key (or index) and value pair. It's also used in the foreach statement. Here are some examples:

    PHP Code:
    // Associative array representing one book:
    // In this case, the key represents a field of data, and the value represents the field's value
    $book = array(
      
    "author" => "Richard Dawkins",
      
    "title" => "The God Delusion",
      
    "isbn" => "0618680004",
      
    "year" => 2006
    );

    // Numeric array representing multiple books
    // In this case, the key represents a book ID, and the value represents the book
    $books = array(
      
    => $book,
    );

    // Foreach
    foreach($books as $index => $book){
      echo 
    "On book #{$index} in collection.\r\n";
      echo 
    "Book data:\r\n";
      foreach(
    $book as $key => $value){
        echo 
    "{$key}{$value}\r\n";
      }

    Like Archer? Check out some Sterling Archer quotes.

  5. #5

    Thread Starter
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: [RESOLVED] What does "=>" do ?

    Thanks

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width