Re: problem in 2 dimensional Array
| From: | Al | Date: | Mon, 27 Oct 2003 03:37:07 +0000 |
| Subject: | Re: problem in 2 dimensional Array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-167671@lists.php.net to get a copy of this message | ||
> 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 as an
> arrgument
In the context of your questions, 2-Dimensional arrays are no different to
1-dimensional arrays.
All global vairables in PHP are stored in the predefined $GLOBALS
associative array, which is automatically global in scope. Each key of the
$GLOBALS array is a name of a global variable. For example, the following
code will print "Hello World":
<?php
function setVarA ( $value ) {
$GLOBALS['varA'] = $value;
}
function echoVarA ( ) {
echo $GLOBALS['varA'];
}
$varA = "Hello";
echoVarA( );
setVarA ( " World");
echo $varA;
?>
Passing an array to a function is no different passing a scalar variable:
<?php
function countArray ( $arrayArgument ) {
return count ($arrayArgument);
}
$array = array ('a', 'b');
echo "The array has ". countArray($array) ." items.";
?>
Cheers,
Al