简体   繁体   中英

Printing an values from a session array in PHP

I'm trying to print a list of values that I've stored in a session-variable array, and all I'm getting is that 'Headers already sent...' error. On the error page I can see the array working, but obviously it won't proceed from there. The line the error mentions is this:

$uploadedfiles = print_r($_SESSION['uploadedfiles']);

The array is declared and values are added to it with this:

array_push($_SESSION['uploadedfiles'], $file_name);

Any thoughts?

Thanks kindly.

print_r() will automatically print to the screen. You need to set the second parameter to true to actually capture it in a variable.

$uploadedfiles = print_r($_SESSION['uploadedfiles'], true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM