Bluehost.com Web Hosting $6.95

Problem in 2 dimensional Array

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-22-2003
Khuram Noman
 
Posts: n/a
Default Problem in 2 dimensional Array

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
Reply With Quote
  #2 (permalink)  
Old 10-22-2003
Marek Kilimajer
 
Posts: n/a
Default Re: [PHP] Problem in 2 dimensional Array

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
>

Reply With Quote
  #3 (permalink)  
Old 10-22-2003
Erwin Moller
 
Posts: n/a
Default Re: Problem in 2 dimensional Array

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 04:26 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0