Sometimes, when programming in PHP, you’ll need to convert an array to JSON. This enables you e.g. to retrieve data serverside through PHP and pass it to the client, which then can process this data with javascript. There are different ways to do that, e.g. via AJAX.
In this article I’ll show you, how easy it is to convert a PHP array into a JSON String.
PHP: Check If A Value Exists In An Array
Let’s say, you have a value like e.g. a name and you’ll find out, whether this value exists in an array of names or not. How could you do this? Well, it’s quite simple. Here I’ll show you how.
JavaScript: Get A Random Item From An Array
In one of my previous posts I’ve shown you how to get a random item from an array in PHP. Well, there is, of course, a way to do this in JavaScript as well. And it’s also very easy. Just declare someting like this:
<script> var allItems = ['A', 'B', 'C', 1, 2, 3, 4, 5]; </script> |
PHP: Find Out The Modification Time Of A File
Do you want to find out the modification time of a file in your PHP script? Well, in this article you’ll find out how easy this is. 😉
PHP: Quickly Generate An Array From Variables With The compact() Function
Do you want to build an array in PHP, which should contain existing variables? Well, there is an easy way to do this. PHP has a very cool function for this to do. You can use the variable’s name as the key and the variables value as the value.
PHP: How Can I Find Out, Whether A Number Is Odd Or Even With The Modulo Operator?
There is a simple way in PHP to find out, wheather a number is odd or even. All you need is the modulo operator.
What is the modulo operator?
The modulo operator in PHP is represented by an %. With this operator you can determine the rest of an interger division.
Here’s an example:
HTML Codes For Playing Cards
Would you like to display playing cards symbols like Diamonds, Hearts, Clubs and Spades on your HTML pages? Well, it’s quite simple. Just use the following HTML codes: Symbol Code HTML Diamonds ♦ ♦ ♦ Hearts ♥ ♥ ♥ Clubs ♣ ♣ ♣ Spades ♠ ♠ ♠ With the playing cards HTML codes you … Read more
3 Great HTML5 Attributes That Simplify Coding
HTML5 offers a lot of new features, which were, in my opinion, long overdue. In this article i will show you three great new HTML5 attributes which will make coding your HTML5 Website easier.
placeholder-Attribute
Do you know this placeholder texts within form fields like e.g. “Enter your email adress here”? Well with HTML5 you can add placeholders quite easily to your form fields. Just add the placeholder attribute to your form tag. No Javascript or other hacks needed anymore.
How To Convert A Decimal Number To A Binary Number
Converting a decimal number to a binary number is easy. You just have to divide the decimal number by 2. If the division yields an integer, note 0, otherwise 1.
Now take the integer part of the division and divide it again by 2. Here, too, the value 0 or 1 is determined analogously.
This is done until the result of the division is 0.
Here is an example: