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
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Thu Nov 02, 2006 6:29 am
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.
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Thu Nov 02, 2006 6:34 am
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.
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Thu Nov 02, 2006 6:41 am
exactly but how to combine them so that i can access them
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Thu Nov 02, 2006 6:47 am
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
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Thu Nov 02, 2006 6:48 am
Code: Select all
$tst = array(1, 2, 3, 4, 5, 6);
$tst1 = array(11, 12, 13, 14, 15, 16);
$a = array($tst,$tst1);
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Thu Nov 02, 2006 6:53 am
and how to set $a array as global
i tried
is it ok
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Thu Nov 02, 2006 6:59 am
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.
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Thu Nov 02, 2006 6:59 am
Don't set it as global. That would be silly. Pass it as an argument.
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Thu Nov 02, 2006 7:01 am
sorry did not understand can you please explain ?
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Thu Nov 02, 2006 7:04 am
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.
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Thu Nov 02, 2006 8:08 am
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
)