This is a discussion on Problem in 2 dimensional Array within the PHP General forums, part of the PHP Programming Forums category; Dear Members i have 2 problems in 2 dimensional array . 1. how to declare global 2 dimensional array in php ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Dear Members
i have 2 problems in 2 dimensional array . 1. how to declare global 2 dimensional array in php 2. how to pass 2 dimensional array in function Waiting for ur soon reply Khuram Noman __________________________________ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com |
|
|||
|
khuram noman wrote:
> Dear Members > > i have 2 problems in 2 dimensional array . > > 1. how to declare global 2 dimensional array in php $GLOBALS['array_name']=array( .... ); > 2. how to pass 2 dimensional array in function Like any other value. > > Waiting for ur soon reply > > Khuram Noman > > __________________________________ > Do you Yahoo!? > The New Yahoo! Shopping - with improved product search > http://shopping.yahoo.com > |
|
|||
|
Khuram Noman wrote:
Hi Khuran, run and study this: --------------------------------- <html> <head> <title>2d test</title> </head> <body> creating the global array. <br> <? // Create a global 2dimensional array named $G. global $G; $G[0]["name"] = "John"; $G[0]["age"] = "19"; $G[1]["name"] = "Sjaak"; $G[1]["age"] = "9"; // check if global: testGlobal (); ?> <hr> <? // Create a new (not global) Array $A , Pass it to a function: $A[0][0] = "Hello, I am element at [0][0]"; $A[0][1] = "yes"; $A[0][2] = "php"; $A[1][0] = "is"; $A[1][1] = "cool."; $A[1][2] = ":-)"; testFunction($A); ?> </body> </html> <? function testGlobal () { // does $G exist? echo "[in testGlobal] 0) first name".$G[0]["name"]." age:".$G[0]["name"]."<br>"; echo "[in testGlobal] 1) first name".$G[1]["name"]." age:".$G[1]["name"]."<br>"; } function testFunction ($something){ // treat $something as a 2-dimensional array echo "something[0][0] contains: ".$something[0][0]."<br>"; echo "something[0][1] contains: ".$something[0][1]."<br>"; echo "something[0][2] contains: ".$something[0][2]."<br>"; echo "something[1][0] contains: ".$something[1][0]."<br>"; echo "something[1][1] contains: ".$something[1][1]."<br>"; echo "something[1][2] contains: ".$something[1][2]."<br>"; } ?> --------------------------------- > Dear Members > > i have 2 problems in 2 dimensional array . > > 1. how to declare global 2 dimensional array in php > 2. how to pass 2 dimensional array in function > > Waiting for ur soon reply > > Khuram Noman > Good luck, Reagrds, Erwin Moller |