gabrielkolbe Posted July 29, 2007 Share Posted July 29, 2007 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; } Quote Link to comment Share on other sites More sharing options...
trq Posted July 29, 2007 Share Posted July 29, 2007 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; } Quote Link to comment Share on other sites More sharing options...
gabrielkolbe Posted July 29, 2007 Author Share Posted July 29, 2007 thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.