Combining Appended Values in PHP Function Output

I have the following PHP function which "renders" an output from appended values:

protected function getFieldRow($label, $value, $encode = true)
{
    if (empty($value))
    {
        return '';
    }       
    return FoxHtmlElem::create()->append(FoxHtmlElem::create('div')->classes('field-title')->text(JFilterInput::getInstance()->clean($label .= ": ")))->append(FoxHtmlElem::create('div')->classes('field-content')->html($encode ? nl2br(FoxHtmlEncoder::encode(JFilterInput::getInstance()->clean($value))) : $value))->render();
}

Which outputs to a list like this:

<div class="field-title">Label : </div><div class="field-content">Value</div>
<div class="field-title">Label : </div><div class="field-content">Value</div>
<div class="field-title">Label : </div><div class="field-content">Value</div>

How can I change the function so that it combines the two appended values inside the same div like this:

<div class="field-content">Label : Value</div>
<div class="field-content">Label : Value</div>
<div class="field-content">Label : Value</div>

Thank you.

Answers


It looks like you want to do this:

<?php

return FoxHtmlElem::create()
->append(FoxHtmlElem::create('div')
->classes('field-content')
->html( JFilterInput::getInstance()->clean($label .= ":&nbsp;"). ($encode ? nl2br(FoxHtmlEncoder::encode(JFilterInput::getInstance()->clean($value))) : $value)))->render();

Just move the label variable into the HTML method instead of creating a separate div.


Need Your Help

How SHOULD you make (and use) static libraries on the iPhone

iphone xcode dynamic static

AFAICS, any serious iPhone developer must make and use static libs on a regular basis, or else condemn themselves to buggy, hard-to-maintain, unwieldy projects. But Apple refuses to provide any off...

php: converting an array of objects to pure array

php jquery laravel

following array is received at server side :