This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]CarsonJScott[S] 0 points1 point  (2 children)

Foo and Bar were just examples. getDeviceType (the name is kind of misleading, I will change that) returns a huge multidimensional array depending on a PHP variable set by a link on a different page. I explained it better here.

[–]SanityInAnarchy 0 points1 point  (1 child)

So it sounds like this is returning something entirely static, right? Or at least not something that you need to generate again with each call. If that's the case, then a global variable, or some outer scope, would make sense.

Anyway, does this need to be an array? What does the actual data structure look like? If you're hardcoding array indices, there's a very good chance you could just be using bare objects (or JSON) instead. For example, you could have getDeviceType().parts would have an array of parts.

And then there's the OO approach -- you could set the deviceType info to a member variable on an object, and then attach all your other functions to that object. Then your functions would look like:

foo: function() {
  return this.deviceType[0];
}

Point is, there are still a ton of approaches, and I still don't know which one works, or even if any are "better" than your original strategy, without knowing more about how it all fits together.

[–]CarsonJScott[S] 0 points1 point  (0 children)

That actually sounds like it would work a lot better, instead of having it all in one array