Array klopt niet
BladiN - 25/09/2004 19:39
Grafische gevorderde
Dit is wat ik heb als array's
$types = array("art" => "Artilleries","cav" => "Cavalries","inf" => "Infantries","nav" => "Naval Units");
$types['art'] = array("cat" => "Catapult");
$types['cav'] = array("kni" => "Knight");
$types['inf'] = array("hop" => "Hoplitai","arc" => "Archer","spe" => "Spearsman");
$types['nav'] = array("gal" => "Galley","car" => "Caravel");
$types = array ( "art" => "Artilleries" , "cav" => "Cavalries" , "inf" => "Infantries" , "nav" => "Naval Units" ) ;
$types [ 'art' ] = array ( "cat" => "Catapult" ) ; $types [ 'cav' ] = array ( "kni" => "Knight" ) ; $types [ 'inf' ] = array ( "hop" => "Hoplitai" , "arc" => "Archer" , "spe" => "Spearsman" ) ; $types [ 'nav' ] = array ( "gal" => "Galley" , "car" => "Caravel" ) ;
ten eerst klopt dit dus al niet omdat hij op deze manier de naam van bv Infantries wegfiltert.
Hoe kan ik het zo doen dat het maar in 1 array hoeft met ondergeschikten (de Spearsman enzo) en dat de naam nog wel werkt?
5 antwoorden
Gesponsorde links
Thomas - 25/09/2004 19:49 (laatste wijziging 25/09/2004 19:50)
Moderator
$types = array();
$types['art'] = array("name" => "Artilleries", "units" => array("cat" = > "Catapult"));
$types['cav'] = array("name" => "Cavalries", "units" => array("kni" => "Knight"));
$types['inf'] = array("name" => "Infantries", "units" => array("hop" => "Hoplitai","arc" => "Archer","spe" => "Spearsman"));
$types['nav'] = array("name" => "Naval Units", "units" => array("gal" => "Galley","car" => "Caravel"));
naam van art:
$types['art']['name'] (dit is een string, levert "Artilleries")
array van units:
$types['art']['units'] (dit is een array, levert array("cat" = > "Catapult"))
unitnaam van Knight in Cavalries:
$types['cav']['units']['kni'] (dit is een string, levert "Knight")
$types [ 'art' ] = array ( "name" => "Artilleries" , "units" => array ( "cat" = > "Catapult" ) ) ; $types [ 'cav' ] = array ( "name" => "Cavalries" , "units" => array ( "kni" => "Knight" ) ) ; $types [ 'inf' ] = array ( "name" => "Infantries" , "units" => array ( "hop" => "Hoplitai" , "arc" => "Archer" , "spe" => "Spearsman" ) ) ; $types [ 'nav' ] = array ( "name" => "Naval Units" , "units" => array ( "gal" => "Galley" , "car" => "Caravel" ) ) ;
naam van art:
$types [ 'art' ] [ 'name' ] ( dit is een string, levert "Artilleries" )
$types [ 'art' ] [ 'units' ] ( dit is een
array , levert
array ( "cat" = > "Catapult" ) )
unitnaam van Knight in Cavalries:
$types [ 'cav' ] [ 'units' ] [ 'kni' ] ( dit is een string, levert "Knight" )
BladiN - 25/09/2004 19:56
Grafische gevorderde
Ok, dat heb ik.. en dan krijg je dit:
foreach($types as $name => $type) {
$tpl->newBlock("type");
$tpl->assign(array("t_name" => $type['name'],
"t_own" => "You Own",
"t_max" => "Max",
"t_amount" => "Amount"
));
foreach($type as $name => $unit) {
$tpl->newBlock("units");
$tpl->assign(array("n_name" => $unit,
"n_own" => "You Own",
"n_max" => "Add",
"no" => $this->no++
));
}
}
foreach ( $types as $name => $type ) {
$tpl -> newBlock ( "type" ) ;
$tpl -> assign ( array ( "t_name" => $type [ 'name' ] , "t_own" => "You Own" ,
"t_max" => "Max" ,
"t_amount" => "Amount"
) ) ;
foreach ( $type as $name => $unit ) {
$tpl -> newBlock ( "units" ) ;
$tpl -> assign ( array ( "n_name" => $unit , "n_own" => "You Own" ,
"n_max" => "Add" ,
"no" => $this -> no ++
) ) ;
}
}
Dat klopt dus ook niet helemaal.. want als er bv de ene 3 heeft en de ander 2, geeft hij bij die ene van 2 één array als naam weer :S hoe doe ik dit goed dan?
Thomas - 25/09/2004 20:01
Moderator
Euh, je hebt 2 foreaches in elkaar met dezelfde aliasen voor keys en values. Gaat dit wel goed ?
BladiN - 26/09/2004 18:03
Grafische gevorderde
Weer een probleem, nu heb ik dit dus:
$types = array();
$types['art'] = array("name" => "Artilleries",
"units" => array("cat" => "Catapult",
"attacks" => array("bui" => "Buildings")
));
$types['cav'] = array("name" => "Cavalries",
"units" => array("kni" => "Knight",
"attacks" => array("cav" => "Cavalries",
"inf" => "Infantries"
)));
$types['inf'] = array("name" => "Infantries",
"units" => array("hop" => "Hoplitai",
"attacks" => array("cav" => "Cavalries",
"inf" => "Infantries",
"arc" => "Archer",
"attacks" => array("cav" => "Cavalries",
"inf" => "Infantries",
"nav" => "Naval Units",
"spe" => "Spearsman",
"attacks" => array("bui" => "Buildings",
"inf" => "Infantries"
)))));
$types['nav'] = array("name" => "Naval Units",
"units" => array("gal" => "Galley",
"attacks" => array("bui" => "Buildings",
"nav" => "Naval Units",
"car" => "Caravel",
"attacks" => array("bui" => "Buildings"
))));
$types [ 'art' ] = array ( "name" => "Artilleries" , "units" => array ( "cat" => "Catapult" , "attacks" => array ( "bui" => "Buildings" ) ) ) ;
$types [ 'cav' ] = array ( "name" => "Cavalries" , "units" => array ( "kni" => "Knight" , "attacks" => array ( "cav" => "Cavalries" , "inf" => "Infantries"
) ) ) ;
$types [ 'inf' ] = array ( "name" => "Infantries" , "units" => array ( "hop" => "Hoplitai" , "attacks" => array ( "cav" => "Cavalries" , "inf" => "Infantries" ,
"arc" => "Archer" ,
"attacks" => array ( "cav" => "Cavalries" , "inf" => "Infantries" ,
"nav" => "Naval Units" ,
"spe" => "Spearsman" ,
"attacks" => array ( "bui" => "Buildings" , "inf" => "Infantries"
) ) ) ) ) ;
$types [ 'nav' ] = array ( "name" => "Naval Units" , "units" => array ( "gal" => "Galley" , "attacks" => array ( "bui" => "Buildings" , "nav" => "Naval Units" ,
"car" => "Caravel" ,
"attacks" => array ( "bui" => "Buildings" ) ) ) ) ;
Maar dat geeft (bij het stukje infantrie)
[inf] => Array
(
[name] => Infantries
[units] => Array
(
[hop] => Hoplitai
[attacks] => Array
(
[cav] => Cavalries
[inf] => Infantries
[arc] => Archer
[attacks] => Array
(
[cav] => Cavalries
[inf] => Infantries
[nav] => Naval Units
[spe] => Spearsman
[attacks] => Array
(
[bui] => Buildings
[inf] => Infantries
)
)
)
)
)
(
[ name] => Infantries
(
[ hop] => Hoplitai
(
[ cav] => Cavalries
[ inf] => Infantries
[ arc] => Archer
(
[ cav] => Cavalries
[ inf] => Infantries
[ nav] => Naval Units
[ spe] => Spearsman
(
[ bui] => Buildings
[ inf] => Infantries
)
)
)
)
)
terwijl het dit moet worden
[inf] => Array
(
[name] => Infantries
[units] => Array
(
[hop] => Hoplitai
[attacks] => Array
(
[cav] => Cavalries
[inf] => Infantries
)
[arc] => Archer
[attacks] => Array
(
[cav] => Cavalries
[inf] => Infantries
[nav] => Naval Units
)
[spe] => Spearsman
[attacks] => Array
(
[bui] => Buildings
[inf] => Infantries
)
)
)
(
[ name] => Infantries
(
[ hop] => Hoplitai
(
[ cav] => Cavalries
[ inf] => Infantries
)
[ arc] => Archer
(
[ cav] => Cavalries
[ inf] => Infantries
[ nav] => Naval Units
)
[ spe] => Spearsman
(
[ bui] => Buildings
[ inf] => Infantries
)
)
)
Gesponsorde links
Dit onderwerp is gesloten .