Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

What is an array property?

What is an array property?

If I were to explain what I know thus far to someone the outside looking in, I would tell them a "key" is like a column name and the "value" is the value associated with that column.

I've been working my way through an array that's loaded with all kinds of bells and whistles and I've got this configuration:

$result = array('stuff'=>array())

I've heard "stuff" referred to as a "key," I've also heard it referred to as a "property." Which is it and, while I've googled the snot out of "array property," I've yet to understand what it is.

What is an array property and could you provide a link to a resource that defines it?

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bruce Gust

ASKER

Chris, this makes sense.

I'm still weeding through that mess you helped me out with weeks ago. I'm determined to "master" this stuff, but it gets tricky when different people use different terms to describe the same thing.

I'm going to explain this back to you and you give me a thumbs up if I'm nailing it.

First off, the term "properties" is better suited for those elements within a class. I understand what you're saying, as far as arrays being a property within a class and I can see why they would be referred to as such.

But...

When you're talking about the elements within an array itself, specifically in the context of the example I cited ($result = array('stuff'=>array())), in that instance, you're probably being a little more clear by referring to "stuff" as a "key" as opposed to a "property."

Correct?
Let me know if what I explained back to you is accurate.
You got it Bruce. Bang on!

The 'stuff' in your array is a key, and if $result was part of a class, that would be a property - "I need the 'stuff' key from the 'result' property"

I know it can be tricky when people use different terms (often incorrectly).

In development, think about properties as being related to OOP, so they belong in classes. FYI - Functions within classes are referred to as Methods! It helps distinguish OOP specific code.
I did find this, but I think at this point, you're getting into some weeds that can make this far more difficult than it needs to be...

https://www.w3schools.com/jsref/jsref_obj_array.asp

Bottom line: Key-> Value BOOM!

You start talking about "properties" and at that point, you're either discussing elements within a method / class or you're getting into some details that aren't usually engaged in the context of regular programming.

Yeah...?
Yeah - all (most?) programming languages have arrays. They're a fundamental part of a language and you'll find yourself using them A LOT!

In very simply terms an array contains a collection of key -> value pairs (that value can be any valid datatype, including arrays if needed!). Generally, this is called an associative array. If you don't have the keys, as in the $days example above, then it's called an indexed array .... or just an array.

As an example, imagine querying your DB for all Customers. Often what is returned is an [indexed] array of associative arrays! The [indexed] array is the list of customers. Each customer is an associative array, containing key -> value pairs. The key is usually the DB Column Name and the value is the data from the DB. Make sense ?

Properties are Class level - not Method level -  although you can access the Class properties from within a Class method!
Sometimes I just like to read these threads without participating.  Is there a language or set of languages that are the context of all these posts? That context seems missing.
Hey Fred. It's posted in the PHP zone ;)
Ah!  Thanks Chris.