<?php
// Even items are words. Odd items represent the number of syllables.
$nouns = array("grass""1""flower""2""willow""2""leaf""1""mountain""2"); // Set the variable $nouns to words and syllables.
$verbs = array("Moving""2""Swaying""2""Growing""2""Swinging back and forth""5"); // Set the variable $verbs to words and syllables.
$adv = array("in the wind""3""slowly""2""well""1""in the soil""3""very quickly""4""""0""very forcefully""5"); // Set the variable $adv to words and syllables.
$adj = array("cool""1""green""1""pretty""2""amazing""3""beautiful""3""lovely""2""colourful""3""turquoise""2""""0"); // Set the variable $adj to words and syllables.

function makehaiku1() { // When makehaiku1() is usedÉ
    
while(1) { // repeat indefinitely.
        
global $nouns$adj// Use the variables defined at the top.
        
$x mt_rand(0count($nouns)); // Set $x to a random number between 0 and the number of items in $nouns.
        
if ($x == 1) { // If $x is oddÉ
            
$x--; // subtract 1 from $x.
        
}
        
$y mt_rand(0count($adj)); // Set $y to a random number between 0 and the number of items in $adj.
        
if ($y == 1) { // If $y is oddÉ
            
$y--; // subtract 1 from $y.
        
}
        
$haiku1 "The ".$adj[$y]." ".$nouns[$x]; // Set $haiku1 to "The (adj) (noun)." This will be used as the first line of the haiku.
        
if ($nouns[$x+1] + $adj[$y+1] == 5) { // If there are 5 syllables in $haiku1É
            
break; // exit the repeating.
        
}
    }
    return 
$haiku1// Pass the value of $haiku1 to whatever is using makehaiku1().
}
function 
makehaiku2() { // When makehaiku2() is usedÉ
    
while(1) { // repeat indefinitely.
        
global $verbs$adv// Use the variables defined at the top.
        
$a mt_rand(0count($verbs)); // Set $a to a random number between 0 and the number of items in $verbs.
        
if ($a == 1) { // If $a is oddÉ
            
$a--; // subtract 1 from $a.
        
}
        
$z mt_rand(0count($adv)); // Set $z to a random number between 0 and the number of items in $verbs.
        
if ($z == 1) { // If $z is oddÉ
            
$z--; // subtract 1 from $z.
        
}
        
$haiku2 $verbs[$a]." ".$adv[$z]; // Set $haiku2 to "(verb) (adverb)."
        
if ($verbs[$a+1] + $adv[$z+1] == 7) { // If there are 7 syllables in $haiku2É
            
break; // exit the repeating.
        
}
    }
    return 
$haiku2// Pass the value of $haiku2 to whatever is using makehaiku2().
}
function 
makehaiku3() { // When makehaiku3() is usedÉ
    
while(1) { // repeat indefinately.
        
global $adj// Use the variables defined at the top.
        
$y mt_rand(1count($adj)); // Set $y to a random number between 0 and the number of items in $adj.
        
if ($y == 1) { // If $y is oddÉ
            
$y--; // subtract 1 from $y.
        
}
        
$haiku3 "It is ".$adj[$y]; // Set $haiku3 to "It is (adjective)."
        
if ($adj[$y+1] == 5) { // If there are 5 syllables in $haiku3É
            
break; // exit the repeating.
        
}
    }
    return 
$haiku3// Pass the value of $haiku3 to whatever is using makehaiku3().
}
$haiku "<div style=\"text-align: center;\">\n".makehaiku1()."<br/>\n".makehaiku2()."<br/>\n".makehaiku3()."</div>"// Display the first line, the second line, and the third line.
echo($haiku);
?>