Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
- Indexed Arrays 5:13
- Adding Array Elements 5:08
- List Quiz 5 questions
- Removing Array Elements 4:50
- Editing Array Elements 1:36
- Modifying Arrays 3 objectives
- Associative Arrays 3:48
- Associative Quiz 5 questions
- Mixing Data Types in Arrays 6:07
- Multidimensional Arrays 6:14
- Multidimensional Arrays 3 objectives
- Sorting Arrays 6:16
- Mixing and Sorting 5 questions
Well done!
You have completed PHP Arrays and Control Structures!

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
In this video, we'll take a look at some of the inner workings of PHP arrays so that you can get the most from your data. In particular, we'll dig into some of the details of how keys work, and what types of values you can use.
Array Keys
- Are case sensitive.
- Must be unique or they will be overwritten.
- Can either be an integer or a string. (The value can be of any type.)
- Can be a combination of integers and strings. Note: ksort will NOT work if numeric and string keys are mixed together.
Key Casting
- Strings containing valid integers will be cast to the integer type. E.g. the key "8" will actually be stored under 8. On the other hand "08" will not be cast, as it isn't a valid decimal integer.
- Floats are also cast to integers, which means that the fractional part will be truncated. E.g. the key 8.7 will actually be stored under 8.
- Bools are cast to integers, too, i.e. the key true will actually be stored under 1 and the key false under 0.
- Null will be cast to the empty string, i.e. the key null will actually be stored under "".
- Arrays and objects can not be used as keys. Doing so will result in a warning: Illegal offset type.
- If multiple elements in the array declaration use the same key, only the last one will be used as all others are overwritten.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Darrell Conklin
Python Development Techdegree Student 22,377 Points4 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up