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;

}

Link to comment
Share on other sites

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;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.