How to print object values in php?
To get more information use this custom TO($someObject) function: Show I wrote this simple function which not only displays the methods of a given object, but also shows its properties, encapsulation and some other useful information like release notes if given.
To show you how it works I will create now some random example class. Lets create class called Person and lets place some release notes just above the class declaration:
Now lets create a instance of a Person and wrap it with our function.
This will output information about the class name, parameters and methods including encapsulation information and the number of parameters, names of parameters for each method, method location and lines of code where it exists. See the output below: (PHP 4, PHP 5, PHP 7, PHP 8) print_r — Prints human-readable information about a variable Descriptionprint_r(mixed print_r(), var_dump() and var_export() will also show protected and private properties of objects. Static class members will not be shown. Parametersvalue The expression to be printed. return If you would like to capture the output of print_r(), use the Return ValuesIf given a string, int or float, the value itself will be printed. If given an array, values will be presented in a format that shows keys and elements. Similar notation is used for objects. When the
ExamplesExample #1 print_r() example
The above example will output: Array ( [a] => apple [b] => banana [c] => Array ( [0] => x [1] => y [2] => z ) ) Example #2
Notes
See Also
liamtoh6 at hotmail dot com ¶ 12 years ago
simivar at gmail dot com ¶ 5 years ago
$input; Matt ¶ 13 years ago
motin at demomusic dot nu ¶ 15 years ago
reinder at fake-address dot com ¶ 16 years ago
'\'' . $name . '\' : ' ) ; thbley at gmail dot com ¶ 16 years ago
print_r_xml($arr,$first=true) { Bob ¶ 13 years ago
henzeberkheij at gmail dot com ¶ 10 years ago
do_print_r($array, $return=false){
bart at mediawave dot nl ¶ 14 years ago
$var1 = 'a'; machuidel ¶ 11 years ago
$array as $key => &$value) Soaku ¶ 4 years ago .
lech ¶ 5 years ago
admin at swivelgames dot com ¶ 14 years ago
[0]=" anon at anon dot com ¶ 14 years ago
; Matthew Ruivo (mruivo at gmail) ¶ 15 years ago
Anonymous ¶ 14 years ago
warhog at warhog dot net ¶ 17 years ago
preda dot vlad at yahoo dot com ¶ 9 years ago
eithed ¶ 10 years ago
afisher8 at cox dot net ¶ 13 years ago
is_array($arrayOfObjectsToHide)) { kurt krueckeberg ¶ 13 years ago
"[$k]".' => ';
schizo do not spamme duckie at gmail dot com ¶ 13 years ago
Alexander ¶ 12 years ago
Simon Asika ¶ 8 years ago
$tabLevel = 1; janci ¶ 14 years ago
= new ReflectionClass('Static'); sebasg37 at gmail dot com ¶ 13 years ago
(); Trixor ¶ 5 years ago
brenden at beagleproductions dot com ¶ 14 years ago
general at NOSPAMbugfoo dot com ¶ 17 years ago
Sumit ¶ 7 years ago
ntd at entidi dot it ¶ 7 years ago
Soaku ¶ 5 years ago
= array(" Enthusiastic PHPers ¶ 15 years ago
helpful at maybe dot com ¶ 14 years ago
anymix dot services at gmail dot com ¶ 5 years ago
How can I print the data of an object in PHP?The print_r() function is a built-in function in PHP and is used to print or display information stored in a variable.. Syntax: print_r( $variable, $isStore ). Parameters: This function accepts two parameters as shown in above syntax and described below.. How can I print the key and value of an object in PHP?php array key value print. function kPrint($key,$obj){. return (gettype($obj)=="array"?( array_key_exists($key,$obj)?$ obj[$key]:("NA")):(gettype($obj)=="object"?( property_exists($obj,$key)?$ ... . //call this function in echo and pass parameters like key and array/object.. What is 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.
How do you access the properties of an object in PHP?The most practical approach is simply to cast the object you are interested in back into an array, which will allow you to access the properties: $a = array('123' => '123', '123foo' => '123foo'); $o = (object)$a; $a = (array)$o; echo $o->{'123'}; // error!
|