Hi,
Any idea what the array(1) means ?
| SitePoint Sponsor |




Hi,
Any idea what the array(1) means ?
http://www.google.com/search?q=php+arrayPHP Code:<Facedown> !php function foo(){return array(1);}; $res = foo(); echo $res[0];
<WhiteVal> Return: 1
http://www.google.com/search?q=php+return





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
So $array[1] is the second element in an array.PHP Code:$sports = array('Football', 'Squash', 'Swimming', 'Pole Hurling');
echo $sports[1]; //Squash
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

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="^$">





Far out, I can't believe it didn't occur to me that the built in function is probably what was intended. Whoops.
Bookmarks