Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php var_dump equivelant or print_r

Tags:

php

var-dump

since I am using json, and ajax it's annoting I cn't pass the value on a valid json.

is there away to just return the value of var dump without it echo,being output to the browser.

e.g.

$data = 'my_data';
get_var_dump($data);//not real func
//should do nothing.
$get['data'] = get_var_dump($data);
$get['error']= false;
echo json_encode($get);
//should be something like 
//{"data,"string(7) my_data","error":false}

or the print_r equivalent I just want to to be assigned to a var instead of outputting it.

or if ur a wordpress fan, difference between bloginfo('url'); and get_bloginfo('url'); should make it easier :)

like image 701
Val Avatar asked Apr 14 '11 15:04

Val


People also ask

What is Var_dump PHP?

PHP | var_dump() Function The var_dump() function is used to dump information about a variable. This function displays structured information such as type and value of the given variable. Arrays and objects are explored recursively with values indented to show structure.

What is the Print_r in PHP?

print_r(variable, isStore) 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 difference between Print_r and echo in PHP?

echo and print are more or less the same. They are both used to output data to the screen. The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions.

What is the difference between print and Print_r?

The print and echo are both language constructs to display strings. The echo has a void return type, whereas print has a return value of 1 so it can be used in expressions. The print_r is used to display human-readable information about a variable.


2 Answers

Sure you can! To do that you will need two PHP buffer functions: ob_start and ob_get_clean. The first one starts buffering, when the second is getting value and cleaning buffer. Example:

ob_start();
var_dump($array);
$value = ob_get_clean();
like image 144
Robik Avatar answered Oct 27 '22 10:10

Robik


print_r has the option for a second parameter. When set to true, it returns the dump as an array instead of displaying it.

http://us2.php.net/print_r

like image 40
Mr. Llama Avatar answered Oct 27 '22 11:10

Mr. Llama