redneonrt Posted September 17, 2010 Share Posted September 17, 2010 Quick question, When I run the code below I get an undefined index error for the array. If I define all the indexes I have no problem making it work correctly. I thought writing it like I did below would define the indexes as they are needed. What am I doing wrong? Thanks for looking, $call_data = array(); if($call_segment['did_digits'] == '3300'){ //Check if call was answered if($call_segment['answered'] == 'No'){ $call_data['3300']['abandoned'] ++; } else{ if(in_array($call_segment['finished_on'],$phoneroom_ext)){ $call_data['3300']['phoneroom'] ++; } elseif(in_array($call_segment['finished_on'],$anoka_ext)){ $call_data['3300']['store'] ++; } } } Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted September 17, 2010 Share Posted September 17, 2010 Without knowing what the specific errors that you are seeing are its hard to tell what you are seeing. However, I suspect that you are seeing warnings and not errors. Those warnings will not break your code and on live servers you usually will not see these errors. However, you should always make sure that they are defined somewhere or to define them if needed. Quote Link to comment Share on other sites More sharing options...
redneonrt Posted September 17, 2010 Author Share Posted September 17, 2010 This is the error I get. A PHP Error was encountered Severity: Notice Message: Undefined index: 3300 Filename: controllers/phone_reports.php Line Number: 234 Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted September 17, 2010 Share Posted September 17, 2010 Yeah if you look at the error it says "Severity:notice". That means that it is just a warning. In the code that you have shown you did not define that index so it is showing you the notice saying so. Good practice is to always define index's and initialize variables. So if you did something like this it should resolve those warnings $call_data = array();//define$call_data['3300']['abandoned'] = 0;$call_data['3300']['phoneroom'] = 0;$call_data['3300']['store'] = 0;if($call_segment['did_digits'] == '3300'){ //Check if call was answered if($call_segment['answered'] == 'No'){ $call_data['3300']['abandoned']++; } else{ if(in_array($call_segment['finished_on'],$phoneroom_ext)){ $call_data['3300']['phoneroom']++; } elseif(in_array($call_segment['finished_on'],$anoka_ext)){ $call_data['3300']['store']++; } }} Quote Link to comment Share on other sites More sharing options...
chintansshah Posted September 17, 2010 Share Posted September 17, 2010 To hide Notice and warning, use error_reporting(0); on top of the page after any included and file and session start; It's good to use error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.