I’m calling either var_dump() or print_r() on an array that has one value in an echo statement:
echo "<br><br>testArray is ==> " . var_dump($testArray) . " <===<br><br>";
Here is the actual output in the browser:
array
0 => string '28' (length=2)
testArray is ==> <===
This is a nuance I don’t get. To me, the order of execution is:
- echo executes and displays
testArray is ==> - the call to var_dump executes and displays the array contents
- then the
<==should execute
Instead of seeing 1, 2 then 3 on the output, I’m seeing 2, 1, 3 in that order.
This is one line of server-side code. What is this nuance?
They do it because they aren’t returning data, they are echoing. You can do
print_r($array, true)to make it return, but var_dump() will need output buffering.If you want it to work the way you’re trying to make it, separate them into distinct calls.