Page 1 of 1

PHP helps

Posted: Fri May 08, 2009 7:35 pm
by noriko94
Could someone help me ?

Create a function that accepts four string variables and returns a string that contains an HTML table element, enclosing each of the variables in its own cell.

Re: PHP helps

Posted: Fri May 08, 2009 7:38 pm
by harlemblues
Actually it's very easy, maybe you just started with php.

By the way, here's the solution:

Code: Select all

function putInTable($s1,$s2,$s3,$s4){
    $table ="<table border=\"1\">" . 
            "<tr><td>" . $s1 . "</td></tr>" . 
            "<tr><td>" . $s2 . "</td></tr>" . 
            "<tr><td>" . $s3 . "</td></tr>" . 
            "<tr><td>" . $s4 . "</td></tr>" . 
         "</table>";
return $table;
}

Re: PHP helps

Posted: Fri May 08, 2009 7:44 pm
by mdk999
eh .. unless you really wanted a a function with 4 params .. I would recommend passing an array but .. you said string so here ya go ..

Code: Select all

 
 
function make_table($str1,$str2,$str3,$str4){
 
$table = <<<FO
 
<table>\r\n
<tr><td>{$str1}</td></tr>\r\n
<tr><td>{$str2}</td></tr>\r\n
<tr><td>{$str3}</td></tr>\r\n
<tr><td>{$str4}</td></tr>\r\n
</table>
FO;
 
return $table;
 
 

Re: PHP helps

Posted: Fri May 08, 2009 8:20 pm
by requinix
Well there goes the "we don't do your homework for you" policy...