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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.