PHP Array, foreach and =>

Discussion in 'PHP' started by imnajam, Jan 21, 2009.

  1. #1
    Hi,

    Can anyone tell me what's the purpose and meaning of "=>" in for each loop?

    what does => reference between $key & $value ($array as $key => $value)
    particularly, take the following example code
     
    imnajam, Jan 21, 2009 IP
  2. misbah

    misbah Active Member

    Messages:
    265
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    68
    #2
    please check this link http://www.php.net/manual/en/language.types.array.php
    array format:
    Array ( key => value)
    Code (markup):
    array sample:
    Array (
    	'foo' => 'bar',
    	'hello' => 'world'
    )
    Code (markup):
    $key : get the value key,
    $value : get value.
    you can use
    foreach ($array as $row)
    Code (markup):
    or
    foreach (array as $key => $row)
    Code (markup):
     
    misbah, Jan 21, 2009 IP
  3. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #3
    If you need to use the key name, then use =>, if you just need to get value of array then you don't need it.
     
    Kaizoku, Jan 21, 2009 IP