When I run the following code:
echo $_POST['zipcode']; print_r($lookup->query($_POST['zipcode'])); ?>
the results are concatenated on one line like so: 10952Array
.
How can I get it to display on separate lines, like so:
08701 Array
The api. php file is in C:\Program Files\xampp\htdocs\project\app\api\api.
It is a built-in function in print_r in PHP that is used to print or display the contents of a variable. It essentially prints human-readable data about a variable. The value of the variable will be printed if it is a string, integer, or float.
var_dump() displays values along with data types as output. print_r() displays only value as output. It does not have any return type. It will return a value that is in string format.
To echo an array, use the format echo ${Array[0]}. Array is your array name, and 0 is the index or the key if you are echoing an associative array.
You might need to add a linebreak:
echo $_POST['zipcode'] . '<br/>';
If you wish to add breaks between print_r() statements:
print_r($latitude); echo '<br/>'; print_r($longitude);
to break line with print_r:
echo "<pre>"; print_r($lookup->query($_POST['zipcode'])); echo "</pre>";
The element will format it with any pre-existing formatting, so \n will turn into a new line, returned lines (when you press return/enter) will also turn into new lines.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With