开发者

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

开发者 https://www.devze.com 2023-01-18 01:43 出处:网络
This is probably obvious but I\'m getting this error: A PHP Error was encountered Severity: Notice Message: Undefined index: outputcards

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['outputc开发者_开发技巧ards'] .= $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!


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)


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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消