array combine problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

array combine problem

Post 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
Last edited by itsmani1 on Thu Nov 02, 2006 6:42 am, edited 1 time in total.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: array combine problem

Post 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.
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

exactly but how to combine them so that i can access them
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post 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
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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);
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

and how to set $a array as global
i tried

Code: Select all

global $a = array();
is it ok
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post 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);
Last edited by itsmani1 on Thu Nov 02, 2006 7:00 am, edited 1 time in total.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Don't set it as global. That would be silly. Pass it as an argument.
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

sorry did not understand can you please explain ?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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.
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post 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
)
Post Reply