Jump to content

Declaring 49 variables efficently o.o


Recommended Posts

Hey i started working on a game from scratch and not using an engine anymore, and im working on my registration page and for my game i have 12 races and its 6 stats and a location that different for each race. So the way i planned to do it was like for example:

if ($_POST['race']='Human'') {

if ($_POST['race']='Dog'') {


So it would be 12 different IF statements declaring 7 variables each o.o is there a more efficient and clean way of doing this?

Link to comment
Share on other sites

Well, when I read the title I was like "what? That little?".

Before you even do anything, PHP already populates around 100 variables, and about five times as many constants.

But anyway..

If you want efficiency, the easiest way would be(as Dayo hinted) an associative array.

Depending on your situation, this could be a few levels deep.

Another way to do it is with an ORM interface, but this requires a little bit more work(depending on your framework).

The benefit that ORM gives you, is that you have an object that can be executed, manipulated and more.

Unlike an array, your output can be dynamic, and callbacks can be set up to perform asynchronous(well almost, it's PHP) actions.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...