473,379 Members | 1,312 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,379 software developers and data experts.

Syntax Error When Passing Array By Reference

I would like to pass an array by reference to a function so that I can modify the contents of the array and effectively "return" that array to the caller.

I tried doing this:

Expand|Select|Wrap|Line Numbers
  1. function MyFunction(&$MyArray)
  2. {
  3.    MyArray[0] = "First";
  4.    MyArray[2] = "Second";
  5. }
  6.  
[Please use CODE tags when posting source code. Thanks! --pbmods]

But I get a sytnax error indicating an unexpected left bracket at the
MyArray[0] = "First"; statement.

I do realize that I could do something like:

Expand|Select|Wrap|Line Numbers
  1. function MyFunction()
  2. {
  3.    MyArray[0] = "First";
  4.    MyArray[2] = "Second";
  5.    return MyArray;
  6. }
  7.  
but I actually need to return multiple arrays from the function, so using the "return" approach doesn't work in my case. Yet, even when I just try to have one passed-in-array-by-reference I get the syntax error.

So, how can I do what I want, which is to pass in (and out) an array by reference?

Roger Garrett
Jun 11 '07 #1
2 1789
Fooey. Never mind. I realized my mistake and it has nothing to do with passing array references.
Jun 11 '07 #2
pbmods
5,821 Expert 4TB
Fooey. Never mind. I realized my mistake and it has nothing to do with passing array references.
Glad to hear you worked it out. What was the problem?
Jun 12 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Christian Brechbühler | last post by:
I get a compile time error that I don't understand. ======================================= begin constructor.cc ====== struct Negate {}; class A { int i; public: A(double x ):...
15
by: chirs | last post by:
I am trying to understand a piece of code. In a javascrpit file, there is a function: function ItemStyle(){ var names=; addProps(this,arguments,names,true); }; In the html file, it calls...
10
by: Adam Warner | last post by:
Hi all, Just before Christmas Chris Torek gave me some great advice about closures in C: <http://groups.google.co.nz/groups?selm=cqcl3k030vj%40news3.newsguy.com&output=gplain> It includes this...
11
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
2
by: Ed Jay | last post by:
I have two functions, one of which is called from within the other, which is called from an HTML page. The called function is passed parameters that I'd like to pass to the argument calling the...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Languageâ€, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
4
by: Michael Holm | last post by:
Calling the function "float dist = Splines.Pick(Vector2(x,y), 5.0f, type, &point);" The function is now defined as float BSpline::Pick(Vector2Coord, float radius, ePickType &type, Vector3...
3
by: DaTurk | last post by:
If I call this method, and pass it a byte by ref, and initialize another byte array, set the original equal to it, and then null the reference, why is the original byte array not null as well? I...
2
by: luis | last post by:
I'm using ctypes to call a fortran dll from python. I have no problems passing integer and double arryas, but I have an error with str arrys. For example: ..... StringVector = c_char_p *...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...

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.