Jump to content

Return... and foreach question...


Aureole

Recommended Posts

Is it not possible to return more than one thing from a function? I tried...

 

return $var, $anothervar; and I get an unexpected "," error.

 

If it's not possible then instead is it possible to do... well, I have this:

 

<?php
foreach($player_stats as $prop => $val)
{
    $formatprop = '<p class="content"><strong>'.htmlentities($prop, ENT_QUOTES).'</strong></p>';
    $formatval = '<p class="content">'.htmlentities($val, ENT_QUOTES).'<p>';
?>
<tr>
<td width="30%" class="black_td"><?php echo $formatprop; ?></td>
<td width="70%" class="gray_td"><?php echo $formatval; ?></td>
</tr>
<?php
}
?>

 

...but I want the foreach to ignore $player_stats['length'], to skip it. Ignore it then go through the rest.

 

Maybe like...

 

<?php
foreach($player_stats as $prop => $val)
{
    if($prop !== 'length')
    {
        $formatprop = '<p class="content"><strong>'.htmlentities($prop, ENT_QUOTES).'</strong></p>';
        $formatval = '<p class="content">'.htmlentities($val, ENT_QUOTES).'<p>';
        // Etc.
    }
}

 

...or is there a better way?

Link to comment
https://forums.phpfreaks.com/topic/80868-return-and-foreach-question/
Share on other sites

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.