Guess Gender ;-)
Nov 22nd
Just a simple function to demonstrate the use of a few very simple but useful functions of PHP. This function simply accepts a parameter ($relation) and returns the “Gender (sex)” of the relationship.
Here’s the function:
<?php
function guessGender($relation)
{
$gen = "";
$relation = ucwords(strtolower($relation));
$relations = array(
"Male" => array("Husband", "Son", "Father", "Brother"),
"Female" => array("Wife", "Daughter", "Mother", "Sister")
);
foreach($relations as $gender => $relationType){
if(in_array($relation, $relationType)){
$gen = $gender;
}
}
return $gen;
}
?>
For the ease of your understanding, I have linked each PHP function, language construct and other statements to Official PHP manual. Simply click on the provided links (in above code) to see the detailed information on each.
Multi-dimensional Arrays
Nov 3rd
Expanding on arrays, but, well…multi-dimentional! Basically meaning you can add an array inside an array.
Arrays
Nov 3rd
Arrays allow you to store a number of data values inside one variables, which makes it easier to read, quicker to assign and easier to access each element!
Recent Comments