SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    return array(1) ?

    Hi,

    Any idea what the array(1) means ?

  2. #2
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <Facedown> !php function foo(){return array(1);}; $res foo(); echo $res[0];
    <
    WhiteVal> Return: 
    http://www.google.com/search?q=php+array
    http://www.google.com/search?q=php+return
    Cross browser css bugs

    Dan Schulz you will be missed

  3. #3
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should most likely be array[1] unless array is the name of a function, in which case it is poorly named.

    Arrays have keys. For an indexed array they are siquential starting at zero
    PHP Code:
    $sports = array('Football''Squash''Swimming''Pole Hurling');
    echo 
    $sports[1];  //Squash 
    So $array[1] is the second element in an array.

    array(1) would be calling a function called array, and passing the value of 1 as an argument.

    http://php.net/array
    http://php.net/functions

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,868
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    array() is the built in function for creating an array so

    return array(1)

    will create a new array containing a single element with a value of 1 and will then return that array. Presumably there are other return statements within the function that return arrays containing other values.

    http://au.php.net/manual/en/language.types.array.php
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Far out, I can't believe it didn't occur to me that the built in function is probably what was intended. Whoops.


Bookmarks

Posting Permissions

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