Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm pretty sure I know what's going on here, your function <code>metersToFeetInches</code> is <code>echo</code>ing a value rather than <code>return</code>ing it.</p> <pre><code>function metersToFeetInches() { echo 'OUTPUT'; } echo 'FIRST '.metersToFeetInches().' LAST'; // Outputs: OUTPUTFIRST LAST </code></pre> <p><code>echo metersToFeetInches()</code> is actually redundant.</p> <p>This is because the function runs before the string you built is actually output. Note that both examples you posted would have this problem. Change your function to <code>return</code> a value instead. Afterwards, any places where you have used it like so:</p> <pre><code>echo 'Something'; metersToFeetInches(); echo 'Something Else'; </code></pre> <p>You'll have to use an <code>echo</code>:</p> <pre><code>echo 'Something'; echo metersToFeetInches(); echo 'Something Else'; </code></pre> <p>Functions should pretty much always <code>return</code> a value. Lesson learned, perhaps?</p> <hr> <p>If you are really in a bind and cannot change the function, you'll have to resort to <a href="http://php.net/manual/en/book.outcontrol.php" rel="nofollow">output buffering</a>:</p> <pre><code>ob_start(); metersToFeetInches($productarea); $metersToFeetInches = ob_get_clean(); echo "&lt;p&gt;&lt;strong&gt;" . __('Area:', 'honegumi') . "&lt;/strong&gt; " . number_format($productarea) . " m² (" . $metersToFeetInches . " ft²)" . "&lt;/p&gt;"; </code></pre> <p>...which is rather silly to have to do.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload