zackcez Posted July 21, 2008 Share Posted July 21, 2008 I'm just wondering if something like this is possible: $PlayerXp[string Skill] = getXp(Skill); And I can simply use it has echo $PlayerXp[Whateverhere]; And the 'Whateverhere' will be the Skill value in getXp.... Link to comment https://forums.phpfreaks.com/topic/115776-solved-php-array/ Share on other sites More sharing options...
kenrbnsn Posted July 21, 2008 Share Posted July 21, 2008 Please explain what you want better. Ken Link to comment https://forums.phpfreaks.com/topic/115776-solved-php-array/#findComment-595189 Share on other sites More sharing options...
zackcez Posted July 21, 2008 Author Share Posted July 21, 2008 I would like to make it so I don't have to define something like this a million times: $PlayerXp["Bla"] = getXp(Bla); And simply make it easier by something like this: $PlayerXp[string Skill] = getXp(Skill); I'm not sure exactly how to explain it tbh :s....So I'll try comparing it to java public int PlayerXp[] Link to comment https://forums.phpfreaks.com/topic/115776-solved-php-array/#findComment-595191 Share on other sites More sharing options...
.josh Posted July 21, 2008 Share Posted July 21, 2008 are you saying you want to automate making an array, like so? for ($x = 0; $x < 10; $x++) { $blah[] = $x; } // you now have an array called $blah // example to loop through array foreach ($blah as $val) { echo "$val <br />"; } Link to comment https://forums.phpfreaks.com/topic/115776-solved-php-array/#findComment-595195 Share on other sites More sharing options...
zackcez Posted July 21, 2008 Author Share Posted July 21, 2008 Kind of, but I don't want the value to be a number... Link to comment https://forums.phpfreaks.com/topic/115776-solved-php-array/#findComment-595198 Share on other sites More sharing options...
.josh Posted July 21, 2008 Share Posted July 21, 2008 ? function getXp($skill) { // do something } for ($x = 0; $x < 10; $x++) { $val = getXp($x); $blah[$val] = $val; } // you now have an array called $blah // example to loop through array foreach ($blah as $val) { echo "$val <br />"; } Link to comment https://forums.phpfreaks.com/topic/115776-solved-php-array/#findComment-595212 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.