Imperialized Imperialized - 2 months ago 8
HTML Question

What causes the HTML to look differently based on the way the PHP is placed?

Here are the photo examples to illustrate what I mean.

Edit:

echo '
<input type="text" name="city" class="" placeholder="City" disabled="true"/>
'.displayStateSelect('state', null).'
<input type="text" name="zip" class="" placeholder="Zip" disabled="true" />';


OR

echo '<input type="text" name="city" class="" placeholder="City" disabled="true" />';

displayStateSelect('state', null);

echo '<input type="text" name="zip" class="" placeholder="Zip" disabled="true" />
</div>


When calling a function during an echo statement:
Code - inline
Photo - inline

Breaking it apart:

Code - Broken Apart
Photo - Broken Apart

-- Aren't these essentially the same? What causes the display order to change? Does it execute the functions response first then echo the rest (as appears?).

Side question, is that bad practice to call inline echo functions? =\

Answer

Your function displayStateSelect('state', null) actually writes the <select> element to the output buffer via an echo or other method instead of using a return which would allow you to use your first method.

ie

function displayStateSelect($state,$something){
    echo '<select><option>1</option><option>2</option>';
}

vs

function displayStateSelect($state,$something){
    return '<select><option>1</option><option>2</option>';
}