Jump to content

Array syntax question


redneonrt

Recommended Posts

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'] ++;
				}
			}
		}

Link to comment
https://forums.phpfreaks.com/topic/213630-array-syntax-question/
Share on other sites

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.

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']++;          }     }}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.