Main Content
If nothing, make it nothing. Archive - Originally posted on "The Horse's Mouth" - 2009-06-02 12:38:43 - Graham Ellis
Here's a peculiar PHP statement I wrote this morning:
if ($aindex[$chk] == "") $aindex[$chk] = "";
What was I doing? I am actually checking to see whether there's anything in an array element and if there isn't (which could be because it's empty or because it doesn't yet exist ), then it should be created if necessary and made to contain an empty string. In PHP, = = tests whether two expressions have an equal values, but = = = tests whether they are of the same type and with equal value.
The important aspect of the assignment that's made above is that it ensures that the array ends up with an element who's key is the contents of $chk, so that later on in my code I can go though all of the items using array_keys even for $chk values for which there is no data.
Some other articles
H999 - Additional PHP Material Image indexer / thumbnail display scripts in PHP Catchable fatal error in PHP ... How to catch, and alternative solutions such as JSON Arrays of arrays - or 2D arrays. How to program tables. Exception handling in PHP This article Extra PHP Examples PHP Techniques - a workshop Flipping images on your web page Script to present commonly used images - PHP Copyright and theft of images, bandwidth and members. More PHP sample and demonstration programs Ordnance Survey Grid Reference to Latitude / Longitude Converting from postal address to latitude / longitude Controlling and labelling Google maps via PHP PHP Standalone - keyboard to screen Drawing hands on a clock face - PHP Drawing dynamic graphs in PHP Sorting people by name in PHP Parallel processing in PHP Dates, times, clickable diarys in PHP Display an image from a MySQL database in a web page via PHP Syntax checking in PHP Reporting on the 10 largest files or 10 top scores PHP - a team member leaves Check your user is human. Have him retype a word in a graphic Hot answers in PHP Presentation, Business and Persistence layers in Perl and PHP PHP Image viewing application PHP - setting sort order with an associative array Merging pictures using PHP and GD Running a Perl script within a PHP page Double Dollars in PHP Stand alone PHP programs Time calculation in PHP the array returned by preg_match_all More maps Ordnance Survey - using a 'Get a map' What and why for the epoch PHP and natural sorting H106 - Arrays Disambiguation - PHP List Splitting the difference with PHP Arrays in PHP - contain different and even mixed data types Learning to program in PHP - Regular Expression and Associative Array examples Sorting data the way YOU want it sorted Increment operators for counting - Perl, PHP, C and others Sorting - naturally, or into a different order Looking up a value by key - associative arrays / Hashes / Dictionaries PHP preg functions - examples and comparision This article When an array is not an array More PHP sample and demonstration programs Testing for one of a list of values. PHP adding arrays / summing arrays Displaying data at 5 items per line on a web page Breaking bread PHP - setting sort order with an associative array Functions and commands with dangerous names H103 - Variables, Operators and Expressions A small teaching program - demonstration of principles only Learning to program - variables and constants BODMAS - the order a computer evaluates arithmetic expressions PHP variables - dynamically typed. What does that mean? Do I need to initialise variables - programming in C, C++, Perl, PHP, Python, Ruby or Java. This article Getting rid of variables after you have finished with them Double Dollars in PHP