From the course: PHP Tips, Tricks, and Techniques

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Array dereferencing

Array dereferencing

- [Narrator] Hi, I'm David Powers, and welcome to this week's edition of PHP Tips and Tricks, designed to help you become a smarter, more productive PHP developer. This time, I'm going to look at a technique known as array dereferencing. But don't let that name put you off. It's very simple. It's also extremely useful. In plain language, it's a direct way of accessing a specific element of an array returned by a function. When you need only that element rather than the whole array, it makes your code shorter and easier to read. To show you how it works, I'm going to use the built-in PHP function getimagesize to get details of this image, hoover.jpg. If you want to follow along, you can download the exercise files for this video. But the script is so simple you can probably type it yourself and use one of your own images. Getimagesize returns an array of up to seven values, so we can use print_r to inspect it. So let's do that by running this script by loading the file into a browser…

Contents