Robimp
Robimp

Reputation: 698

Code Igniter / PHP - Undefined index? Easy points for someone

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?

Thank you!

Upvotes: 0

Views: 13758

Answers (4)

Vishal
Vishal

Reputation: 11

I was facing the same problem, but in my case, I was checking if a particular index exists or not in the array, so my initial code was like:

if ($arr_name[$key] != "")

This used to give me error of 'Undefined Index: '. I later used array_key_exists to check whether the key exists or not & that solved the problem. The warnings disappeared.

if (array_key_exists($key, $arr_name))

Upvotes: 1

Gerardo Jaramillo
Gerardo Jaramillo

Reputation: 485

I had the same problem, in my case was because I had a multidimensional array, so when you try to reference to the item, it was inside another array on top of it.

This error, is given because no the index does not exist in that array.

try outputting the array with print_r to see the structure of the array.

Upvotes: 0

Ascherer
Ascherer

Reputation: 8093

before the line there, just add

$out = array();
$out['outputcards'] = '';

should knock it out. or if you are lazy (and i do not suggest or admire this), put a @ infront of the line

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

Upvotes: 0

CharlesLeaf
CharlesLeaf

Reputation: 3201

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)

Upvotes: 3

Related Questions