At the risk of self-embarrassment, could anyone tell me how to use return here:

function dayCount() {

    for ($dayBegin = 1; $dayBegin < 32; $dayBegin++)
    {
      "<option value=\"".$dayBegin."\">".$dayBegin."</option>";
    }
}

My issue is that I am passing this function to Smarty via

$dayCount = dayCount();
$smarty->assign('dayCount', $dayCount);

and

{$dayCount}

but instead the HTML is going straight to the buffer, right before <html> (thanks Hamish), not inside the HTML element I want.

Any help on this?

share|improve this question

feedback

1 Answer

up vote 2 down vote accepted

You need to build up the return statement

function dayCount() {
    $return = array();
    for ($dayBegin = 1; $dayBegin < 32; $dayBegin++)
    {
      $return[] = "<option value=\"".$dayBegin."\">".$dayBegin."</option>";
    }
    return $return;
}

Although this is building up an array like you asked. When outputting it, you would need to implode it.

implode('', $dayCount);

Or otherwise, build up a string instead of an array.

share|improve this answer
Jacob, you nailed it! Thanks so much for helping - works a treat. I had tried several versions using return but they always output 'array' -- implode was always missing!! – torr Feb 12 '11 at 4:31
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.