Join Kevin Skoglund for an in-depth discussion in this video Delete elements from arrays, part of Easy PHP Projects: Single-Serving Sites.
- In the last movie, we created a Single-Serving Site…that returns text with a random styling applied to it.…But we discovered a problem,…when the randomly chosen text color…is the same as the randomly chosen background color,…you can't read the text.…In this movie, we'll learn how to solve this problem…while also learning an interesting quirk of PHP.…What we need to do…is to remove the selected background color…from the possible color choices…before we randomly pick the text color.…You may be thinking,…great, let's go to the php.net website…and look up the function for removing an element…from an array.…
The problem is there isn't one.…To me, this is one of the most surprising parts of PHP.…There is no array delete.…Instead we have to write our own.…I'm going to show you three different ways to do it.…One using unset,…one using array splice,…and one using array diff.…And you're going to learn the pitfalls of each one.…Let's start by opening up our text editor and starting…a new document that we can use for our experiments.…
- Finding and validating an IP address with PHP
- Parsing the HTTP request for browser details
- Comparing dates and times in PHP
- Randomizing data with PHP
- Styling page content dynamically
- Generating random sentences
Skill Level Beginner
1. What is My IP Address?
2. Browser Mirror
3. Is it New Years Yet?
4. Random Data and Styling
5. Random Phrase Generator
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.