Click here to get back home

returning an array

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
returning an array Jeff 06-20-2008
Posted by Jeff on June 20, 2008, 10:43 am
Please log in for more thread options
I'd like to do this:

function makeAnArray(){
$array = array('one'=>'1','two'=array('more than one'=>'dimension'));

return $array;
}

$a = makeAnArray();

// $a is ('one'=>'1','two'=array('more than one'=>'dimension'))

But with the right syntax. How do I do this?

(in perl I'd return a reference and then do a type conversion)

Jeff

Posted by Iván Sánchez on June 20, 2008, 10:55 am
Please log in for more thread options
Jeff wrote:

> $array = array('one'=>'1','two'=array('more than one'=>'dimension'));

$array = array('one'=>'1','two'=>array('more than one'=>'dimension'));


--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

A bus station is where buses stop. A train station is where trains stop. On
my desk, there is a workstation...

Posted by Jeff on June 20, 2008, 11:12 am
Please log in for more thread options
Iván Sánchez Ortega wrote:
> Jeff wrote:
>
>> $array = array('one'=>'1','two'=array('more than one'=>'dimension'));
>
> $array = array('one'=>'1','two'=>array('more than one'=>'dimension'));
>
>
Yes, a typo. The actual code though is drawing from an unserialized
file, so I know the syntax php generated is corrected is correct. I also
checked the array just before it got returned and it looked fine.

Are you saying that I can return an array that way?

Jeff

Posted by Captain Paralytic on June 20, 2008, 11:15 am
Please log in for more thread options
> Iv=E1n S=E1nchez Ortega wrote:
> > Jeff wrote:
>
> >> $array =3D array('one'=3D>'1','two'=3Darray('more than one'=3D>'dimens=
ion'));
>
> > =A0 $array =3D array('one'=3D>'1','two'=3D>array('more than one'=3D>'di=
mension'));
>
> Yes, a typo. The actual code though is drawing from an unserialized
> file, so I know the syntax php generated is corrected is correct. I also
> checked the array just before it got returned and it looked fine.
>
> =A0 =A0Are you saying that I can return an array that way?

Yes, didn't you think of trying it?

I find it a lot quicker to try simple things like this out instead of
writing a post to a forum such as this.


Posted by Jeff on June 20, 2008, 3:22 pm
Please log in for more thread options
Captain Paralytic wrote:

My apologies...

>> Iván Sánchez Ortega wrote:
>>> Jeff wrote:
>>>> $array = array('one'=>'1','two'=array('more than one'=>'dimension'));
>>> $array = array('one'=>'1','two'=>array('more than one'=>'dimension'));
>> Yes, a typo. The actual code though is drawing from an unserialized
>> file, so I know the syntax php generated is corrected is correct. I also
>> checked the array just before it got returned and it looked fine.
>>
>> Are you saying that I can return an array that way?
>
> Yes, didn't you think of trying it?

I tried this in a function in a class, and sprinkled in some echos to
track the data to see where the problem was.

When I try the very same script now, it works. Perhaps I made some
other mistake... Unfortunately, it's not the craziest thing (not
programming though) that's happened today!

Jeff
>
> I find it a lot quicker to try simple things like this out instead of
> writing a post to a forum such as this.
>

Similar ThreadsPosted
Returning a 2 dimensional array November 3, 2005, 12:10 pm
returning an array from a function May 25, 2006, 6:56 am
Query returning array April 19, 2007, 11:45 pm
Returning an array from javascript to php variable January 4, 2006, 3:27 pm
php extension: returning array of arrays January 12, 2006, 10:39 pm
Arrays : returning a reference to an array item ?? August 11, 2004, 7:58 am
Returning NULL vs. returning FALSE November 18, 2005, 8:52 am
SQL not returning value even though it's there... November 30, 2004, 3:38 am
PHP and returning references September 9, 2004, 5:05 am
returning a true 404 January 17, 2006, 11:18 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap