All things being equal, they (equal things) are not always so in PHP. It's more of...it depends on what you mean by 'equal.' No, this isn't a case of, "it depends what 'is' is" ... or is it?
There are times when you create an array based on a stream of incoming data, and in doing so, are blissfully (or not) ignorant of the keys. How do you get the first member from the array in that case?
For example, if I have an array based on user ID's, which looks like this:
Recently, I had the need to determine whether an array had duplicate values in it. It didn't matter what the duplicate values were, or how many duplicates there were, either of which can be answered with array_count_values(), I just needed to know whether there were any at all; a boolean answer.
There are a lot of ways to approach it, but I found this to be the the most minimal:
$temp_array = array_unique($original_array);
$duplicates = sizeof($temp_array) != sizeof($original_array);
It seems crazy that php doesn't have a native roundDown function.
It does have round(), which has various modes, but they only provide for rounding down if the starting value is < .5 In some cases, one must round up (the number of boxes needed to hold a quantity of items), but in some, it is necessary to always round down, in particular anywhere that a fraction of something makes no sense because the item is either whole or not.
There are numeric ways to accomplish this, such as:
$rounded_value = floor($value / 10^x) * 10^x
I spent the usual two lifetimes getting xdebug working (again) after upgrading to a new major version of phpStorm. Finally, I could debug a standalone php script in the IDE, but all attempts to do so from the browser were fruitless.
It turns out that phpStorm and the browser were using different versions of php.
Things to do (note that I am using Macports):
I've been through more IDE's than I can remember, but I may have stumbled onto a winner.
Sometimes, the guys controlling the synapses are asleep at the switch, and things I've always known are momentarily gone. It's one thing when I know that to be the case — knowing what I don't know — such as seeing an actress on the screen and being asked who it is. I knew until I was asked. It's not knowing that I don't know that's the bigger problem...not realizing that I've forgotten, because the switchman hasn't fallen asleep, he's thrown the wrong switch.
We could create a page template for the page on which we want it. If the requirement is static and small, that is a way to do it, though putting the script directly in the template is not the best-practices way to do it, for several reasons.
Whenever I sit down to design the architecture of a new application, I sit back and ponder. For the past few years, my decision continues to be: php.
I have read many blog entries on the merits of choosing php, ruby or java, and theories on why programmers make choices in opposition to the blogger's. It's my turn to weigh in, for what it's worth.
In the previous blog entry, 3. Are You Odd?, I referred to determining a leap year still being a manual programming process in many cases. There are certainly umpteen library functions out there to do it, but it's simple to do and a nice programming exercise for function writing.
How does one determine if a given year is a leap year? It's a common belief that if the year is evenly divisible by 4, that it is a leap year. That is true most of the time, but not always.
The rule for determining a leap year is this: