t56k
t56k

Reputation: 6981

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.

Upvotes: 2

Views: 2757

Answers (1)

John Conde
John Conde

Reputation: 219794

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);

Upvotes: 5

Related Questions