Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display print_r on different lines?

Tags:

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 
like image 369
ssvarc Avatar asked Dec 15 '11 07:12

ssvarc


People also ask

Where does Print_r output?

The api. php file is in C:\Program Files\xampp\htdocs\project\app\api\api.

Where do you use Print_r () statement?

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.

What is the difference between Echo print Print_r and Var_dump?

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.

How do you echo an array?

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.


2 Answers

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); 
like image 159
span Avatar answered Sep 22 '22 18:09

span


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

like image 27
Sen Sokha Avatar answered Sep 19 '22 18:09

Sen Sokha