By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,745 Members | 1,889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,745 IT Pros & Developers. It's quick & easy.

about return a array

P: n/a
When I write this codes:

<?
function r_array(&$array){
for($i=1;$i<5;$i++) {
for($j=1;$j<5;$j++) {
$array[i][j] = "d";
}

}
}

r_array($array2);
print_r($array2);
echo $array[1][1];
?>

it display in the brower like this:

Array ( [i] =Array ( [j] =d ) )

And this means $array[1][1] can't be used. And what's the problem?

I want return a 2D array and use it like $array[1][1],what should I
do?

Regards!

Apr 24 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"cocobear" <co*******@gmail.comwrote in message
news:11**********************@c18g2000prb.googlegr oups.com...
| When I write this codes:
|
| <?
| function r_array(&$array){
| for($i=1;$i<5;$i++) {
| for($j=1;$j<5;$j++) {
| $array[i][j] = "d";
| }
|
| }
| }
|
| r_array($array2);
| print_r($array2);
| echo $array[1][1];
| ?>
|
| it display in the brower like this:
|
| Array ( [i] =Array ( [j] =d ) )
|
| And this means $array[1][1] can't be used. And what's the problem?
|
| I want return a 2D array and use it like $array[1][1],what should I
| do?

ummmm...put a $ in fron of i and j.

:)
Apr 24 '07 #2

P: n/a
On Apr 24, 6:36 am, cocobear <cocobe...@gmail.comwrote:
When I write this codes:

<?
function r_array(&$array){
for($i=1;$i<5;$i++) {
for($j=1;$j<5;$j++) {
$array[i][j] = "d";
}

}

}

r_array($array2);
print_r($array2);
echo $array[1][1];
?>

it display in the brower like this:

Array ( [i] =Array ( [j] =d ) )

And this means $array[1][1] can't be used. And what's the problem?

I want return a 2D array and use it like $array[1][1],what should I
do?

Regards!
change $array[i][j] = "d";
to $array[$i][$j] = "d";
Apr 25 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.