phpstringconcatenationundefined-index

Concatenation assignment on undeclared variable emits Undefined index error


This is probably obvious but I'm getting this error:

A PHP Error was encountered

Severity: Notice

Message: Undefined index: outputcards

Filename: controllers/site.php

Line Number: 49

Here's the line in question:

$out['outputcards'] .= $this->load->view('client_view_data',$data, TRUE);

which is inside a for loop, and being used in the view as echo $outputcards.

All works fine, but the error is there at the top.

Any ideas?


Solution

  • You are concatenating new data to the $out['outputcards'], but the very first time you do this the $out['outputcards'] probably does not exist yet. So if you have a array called $out, before you start the loop that contains that code, simply do a $out['outputcards'] = ""; (assuming you are concatenating strings)