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!
PHP

Avatar of undefined
Last Comment
hypercube
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Bruce Gust
Bruce Gust
Flag of United States of America image

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?
Avatar of Bruce Gust
Bruce Gust
Flag of United States of America image

ASKER

Let me know if what I explained back to you is accurate.
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

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.
Avatar of Bruce Gust
Bruce Gust
Flag of United States of America image

ASKER

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...?
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

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!
Avatar of hypercube
hypercube
Flag of United States of America image

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.
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Hey Fred. It's posted in the PHP zone ;)
Avatar of hypercube
hypercube
Flag of United States of America image

Ah!  Thanks Chris.
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo