Create a definition list from a function in PHP
Description
The following code shows how to create a definition list from a function.
Example
<!DOCTYPE html>/* w ww .j av a2s . c o m*/
<html>
<body>
<h2>A function to create a definition list</h2>
<?php
$iterations = 10;
function defList( $contents ) {
$markup = "<dl>\n";
foreach ( $contents as $key => $value ) {
$markup .= " <dt>$key</dt><dd>$value</dd>\n";
}
$markup .= "</dl>\n";
return $markup;
}
$myBook = array( "title" => "The Grapes of Wrath",
"author" => "John Steinbeck",
"pubYear" => 1939 );
echo defList( $myBook );
?>
</body>
</html>
The code above generates the following result.