Jump to content

how do I place various PHP action in one variable?


gabrielkolbe

Recommended Posts

Hi, I have this script, it works outside the function, no probs with it BUT I need to place the output of the function in one string in order to return in how do I do it??

 

$input = array('apple', 'orange', 'monkey', 'potato', 'cheese', 'badger', 'turnip');
$cols = 2;

function table_columns($input, $cols) {
[color=red]	
$i=0;
echo = '<table border=1>
	<tr>';
foreach ($input as $in){
$i++;
echo = '<td>'.$in.'</td>';
if($i==$cols){
echo = '</tr><tr>';
$i=0;
}
}
echo = '</tr><table>';[/color]

the bits in red should be placed in a variable called output

return $output;

}

function table_columns($input, $cols) {	
$i=0;
$output .= '<table border=1>
	<tr>';
foreach ($input as $in){
  $i++;
  $output .= '<td>'.$in.'</td>';
  if($i==$cols){
    $output .= '</tr><tr>';
    $i=0;
  }
}
$output .= '</tr><table>';
        return $output;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.