cs.punk Posted February 6, 2011 Share Posted February 6, 2011 Hey guys it's been a long time, but I am back with php! Anyway here's my dilemma: test.php <?php <?php $name = array('Chris', 'Bob', 'Jack'); $names = print_r($name); ?> Simple enough right? Well although I am not printing/echoing these results to screen it does it automatically. Meaning when I point my browser to test.php it outputs this: Array ( [0] => Chris [1] => Bob [2] => Jack ) Rather than only assigning the value to the $names variable, which is what I would expect it to do. Is this normal behaviour or is there something I can change on php.ini? Thank you! Link to comment https://forums.phpfreaks.com/topic/226883-print_r-automatically-echos-contents/ Share on other sites More sharing options...
Fergal Andrews Posted February 6, 2011 Share Posted February 6, 2011 Hi cs.punk, You can capture the output of print_r instead of echoing it by adding a return value: print_r($myArray, true); Try this with your code: <?php $name = array('Chris', 'Bob', 'Jack'); $names = print_r($name, true); echo $names; ?> cheers, Fergal Link to comment https://forums.phpfreaks.com/topic/226883-print_r-automatically-echos-contents/#findComment-1170649 Share on other sites More sharing options...
cs.punk Posted February 6, 2011 Author Share Posted February 6, 2011 Haha dam I should have read the manual! Thank you! Link to comment https://forums.phpfreaks.com/topic/226883-print_r-automatically-echos-contents/#findComment-1170650 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.