Page 1 of 1

array combine problem

Posted: Thu Nov 02, 2006 6:29 am
by itsmani1

Code: Select all

$tst = array(1, 2, 3, 4, 5, 6)
$tst1 = array(11, 12, 13, 14, 15, 16)
here i have three arrays, I want to add these all three in a way that i would be able to access them all
like if i get $a[0][0] outut should be 1 and so on

Re: array combine problem

Posted: Thu Nov 02, 2006 6:34 am
by onion2k

Code: Select all

$a[] = array(1, 2, 3, 4, 5, 6);
$a[] = array(11, 12, 13, 14, 15, 16);
$a[] = array(21,22, 23, 24, 25, 26);
Obviously they'll be zero indexed, so rather than $a[1][1] you'd use $a[0][0] to reference 1.

Posted: Thu Nov 02, 2006 6:41 am
by itsmani1
exactly but how to combine them so that i can access them

Posted: Thu Nov 02, 2006 6:47 am
by itsmani1
Array ( [THISID] => 1987 [THISNAME] => Alliance Theatre [ST] => GA )
Array ( [THISID] => 238 [THISNAME] => Broward Center Amaturo [ST] => FL )
Array ( [THISID] => 536 [THISNAME] => Fabulous Fox Theatre - St. Louis [ST] => MO )
Array ( [THISID] => 2233 [THISNAME] => Ford's Theatre [ST] => DC )
Array ( [THISID] => 657 [THISNAME] => Goodman Theatre - Albert [ST] => IL )


basically i need to add all these above mentioned arrays so that i can access them easily by using foreach look

Posted: Thu Nov 02, 2006 6:48 am
by onion2k

Code: Select all

$tst = array(1, 2, 3, 4, 5, 6);
$tst1 = array(11, 12, 13, 14, 15, 16);

$a = array($tst,$tst1);

Posted: Thu Nov 02, 2006 6:53 am
by itsmani1
and how to set $a array as global
i tried

Code: Select all

global $a = array();
is it ok

Posted: Thu Nov 02, 2006 6:59 am
by itsmani1
I tried this but not working

Code: Select all

<?PHP
	function startElement($parser, $name, $attrs)
	{
		global $tt;
		global $a = array();
		
		if($name == "ROW")
		{
			 //print_r($attrs);
			 $a = array($attrs);
			print_r($a);
		}
	}
?>
print_r($a);

Posted: Thu Nov 02, 2006 6:59 am
by onion2k
Don't set it as global. That would be silly. Pass it as an argument.

Posted: Thu Nov 02, 2006 7:01 am
by itsmani1
sorry did not understand can you please explain ?

Posted: Thu Nov 02, 2006 7:04 am
by onion2k
itsmani1 wrote:sorry did not understand can you please explain ?
Never use global. It's very bad practise and it'll break your code. Pass everything your function needs as arguments.

Posted: Thu Nov 02, 2006 8:08 am
by itsmani1
tried this but got a problem its not saving in correct way and i don't know how to parse it?

Code: Select all

for($i=0; $i<9; $i++)
{
$a = array($a,$attrs);
}
need like this:

array(
array,
array,
array
)