473,396 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

returning an array

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
Jun 27 '08 #1
5 1052
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...
Jun 27 '08 #2
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
Jun 27 '08 #3
On Jun 20, 4:12*pm, Jeff <jeff@spam_me_not.comwrote:
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 find it a lot quicker to try simple things like this out instead of
writing a post to a forum such as this.

Jun 27 '08 #4
Jeff schreef:
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
Yes,

$myArr = array (
1 =12,
50 ="hello fifty",
"IamAssoc" =array(23,45,77),
"meToo" =array("one" =1, "two" =2)
)

is perfectly fine.

Regards,
Erwin Moller
Jun 27 '08 #5
Captain Paralytic wrote:
On Jun 20, 4:12 pm, Jeff <jeff@spam_me_not.comwrote:
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.
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Krackers | last post by:
How do you write a function which returns a reference to an array. I can only get a function to return a copy of the array itself. I've had a look at some other threads in this group an the return...
7
by: BrianJones | last post by:
Hi, if you have a function, how is it possible to return an array? E.g.: unsigned long function(...) // what I want to do, obviously illegal I do know such would be possible by using a dynamic...
10
by: Fraser Ross | last post by:
I need to know the syntax for writing a reference of an array. I haven't seen it done often. I have a class with a member array and I want a member function to return an reference to it. ...
41
by: Materialised | last post by:
I am writing a simple function to initialise 3 variables to pesudo random numbers. I have a function which is as follows int randomise( int x, int y, intz) { srand((unsigned)time(NULL)); x...
3
by: Faustino Dina | last post by:
Hi, The following code is from an article published in Informit.com at http://www.informit.com/guides/content.asp?g=dotnet&seqNum=142. The problem is the author says it is not a good idea to...
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
17
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ...
13
by: Karl Groves | last post by:
I'm missing something very obvious, but it is getting late and I've stared at it too long. TIA for responses I am writing a basic function (listed at the bottom of this post) that returns...
0
by: anuptosh | last post by:
Hi, I have been trying to run the below example to get a Oracle Array as an output from a Java code. This is an example I have found on the web. But, the expected result is that the code should...
5
by: ctj951 | last post by:
I have a very specific question about a language issue that I was hoping to get an answer to. If you allocate a structure that contains an array as a local variable inside a function and return...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.