PHP Error - Undefined Index problem

Posted on 2012-09-09
Last Modified: 2012-09-09
I am receiving the following error:

A PHP Error was encountered

Severity: Notice

Message: Undefined index: Jun 10, 2011

Filename: controllers/taxCalcFunction.php

Line Number: 5

Open in new window

And here is the code in question:

	$arr_bill_dates = array();
	foreach($data['billing_events'] as $billdate) {
		foreach($billdate as $event) {
			$key = array_keys($event);
			$arr_bill_dates[$key[0]]++; } } //<- ERROR ON THIS LINE
	$data['arr_bill_dates'] = $arr_bill_dates;

Open in new window

I don't understand why I am getting this error because the variable $arr_bill_dates is defined at the beginning before the loop.  Why is this causing an error?  Thanks.
Question by:DanielAttard
    LVL 30

    Accepted Solution

    Because 'arr_bill_dates' is not recognized as a valid index for $data array, that is $data['arr_bill_dates'] item simply doesn't exist. I can't know why, but this is what you have to investigate.


    Author Comment

    Thanks for the advice.  I'll take a step back and look at some of the earlier code to see what's happening there.
    LVL 107

    Assisted Solution

    by:Ray Paseur
    You can use var_dump() to print out the contents of a variable.  It makes debugging a lot easier!

    Author Comment

    Thanks Ray.  I've implemented one of the many different flavors of debug tools found on the link you provided.  Now I've got tons of useful, well-formatted information being presented to me to help solve this issue.

    Great idea.  Thank you.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: Create Mobile App Prototypes with Adobe XD

    This is a project-based course: we go through all the steps of creating a prototype from start to finish, using all the tools and features currently available in Adobe XD. You can complete the course in less than a day, plus all project files and fonts are included.

    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now