2

I'm a fresh grad, and I just started workingin real world projects. I'm basically using PHP most of the time. I just figured out that most of the solutions I came out with for most of the problems, is involving using an array in somehow. What Am I doing wrong here? How could I unlearn this and always think of something else? Or is it the fault of the language?

2
  • What kind of problems are you looking at?
    – XQYZ
    Commented May 9, 2012 at 0:10
  • 4
    Minor note: sometimes excessive use of arrays (or collections, in other languages) can be a symptom of object denial. Specifically if the content of the array is "structured" in that the first element has a specific meaning and the second element has a different specific meaning, then someone's probably building an "object" disguised as an array. If, however, the elements in the array are all of the same type (i.e. they are interpreted in the same way), then it's a "true" array. That's not specific to PHP, but can happen in pretty much all languages. Commented May 9, 2012 at 5:41

3 Answers 3

4

I've been using PHP for, I think, around 6 or 7 years now. I find myself using arrays quite a bit. With built in sorting and looping functions, they are easy to work with and help manipulate data the way I need to.

Where you say "...or is it the fault of the language?" It's only a fault if it causes some problem, prevents you from solving a problem, or uses more resources than you might otherwise use, so I'd say there's likely no fault to be had.

3

Most programming is going to involve manipulating a collection of some sort, of which the array is the most basic type. Other languages use Lists, Vectors and Dictionaries\Associative arrays a lot as well but PHP utilizes the same syntax for both associate arrays and numeric arrays.
Do you want to use other data types? Sure, when you have a demonstrated performance problem or need a particular structure like a stack or queue. Using a lot of various search structures and various sort and search algorithms for large data sets is often unnecessary due to databases. This is of course provided you understand how to structure and index your tables properly. If it helps, a few Fortran programmers used to think about various data structures as types of arrays.

0

Depending on the problem, if it includes data or collections it is usual that you may come up with a solution using arrays. But if you're thinking that it's the programming language's fault, then think again; problem is the way of how you think solutions.

Not the answer you're looking for? Browse other questions tagged or ask your own question.