PHP: Get A Random Item From An Array

In PHP it’s easy to work with arrays. Just declare someting like this:

$arrX = array("Kay", "Joe","Susan", "Frank");

Now you can access the values with their index (which starts a 0 for the first item).

// output "Kay"
echo $arrX[0];
// output "Susan"
echo $arrX[2];

PHP offers you several ways to get a random value of the array. One simple way is by using the array_rand() function. array_rand() expects the array as a parameter and returns a random index value as integer which then can be used to get the array value.

Read more

How to insert special characters like &, < and > into a JSF component

If you want to insert a character like & e.g. within a JSF (Java Server Faces) component’s value attribute, you might get an error. To avoid this you must insert a HTML-Entity for the character. Here is a short list for common characters which you might need to replace in your JSF component. Character Entity … Read more