undefined offset php

PHP Notice:  Undefined offset: 10 in file.php on line 112
PHP Notice:  Undefined offset: 11 in file.php on line 112

                    foreach ($traceroute as $key => $result) {
                    $ip = $result['ip'];
                    $datetime = $result['datetime'];
                    $hop = $result['hop'];
                if(isset($arrayip[$ip])) {
                    if ($ip == $array[$hop]['ip']) {                           < This is line 112
                        $datetime = $array[$hop]['datetime'];
                        }
                }


Guessing this can't be fixed without having to show all of my code... which I can't do.
projectsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
Well it's telling you there is no such index as 10 in the array
0
projectsAuthor Commented:
Ok but how do I fix this problem without having to call a programmer :)
0
Ahmed MerghaniSoftware EngineerCommented:
Replace you code with this:
foreach ($traceroute as $key => $result) {
                    $ip = $result['ip'];
                    $datetime = $result['datetime'];
                    $hop = $result['hop'];
                if(isset($arrayip[$ip])) {
                    if ($ip == @$array[$hop]['ip']) {                           < This is line 112
                        $datetime = $array[$hop]['datetime'];
                        }
                }

Open in new window

I just add "@" before the array.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

GaryCommented:
if(isset($arrayip[$ip]) && isset($array[$hop]['ip'])) {
            if ($ip == $array[$hop]['ip']) {
                $datetime = $array[$hop]['datetime'];
    }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
Undefined offset is closely related to undefined index. In both cases you're telling PHP to find information that does not exist.  In the case of undefined offset the array is numerically indexed and there is no position with the numerical index that you've requested.  With undefined index you're using a named position in an associative array, and the array index name does not exist.

How / whether you choose to fix this is going to be dependent on what you want for output.  Without seeing the data and understanding the larger context it's not really possible to give you a "good" answer, but we might get lucky.  It appears to be an issue of data inconsistency -- the programming expects data that is somehow missing.  Here are some of the things only you can know about this application.

1. Is it OK to ignore this Notice, and just skip over the missing data?
2. Is it necessary to trap the condition that is indicated by the missing data?  
3. Perhaps there is another programmatic or manual process that is needed to "scrub" the data?  
4. Or perhaps there is an exception report that would be needed here?

If you know those answers then you can work around the missing data.  The exact techniques would be different, depending on your exact needs.
0
projectsAuthor Commented:
@fishboy2000sd fix seems to be working but Gary added one also.

Guess there is no way of knowing which fix is right yet but the error in the logs have gone away.
I've tested it a few times now. Won't really know until certain conditions arise I guess.

What I need to make sure of is that there is no limiter causing results to be truncated but I won't know that unless I watch for a while I think.
0
GaryCommented:
Using @ basically skips the error reporting so you could end with variables that are not correctly set
http://us3.php.net/manual/en/language.operators.errorcontrol.php

My code checks it actually exists in the first place
0
projectsAuthor Commented:
Yes, I would prefer not to just hide the problem but to guesstimate a fix for now while keeping an eye on the logs. Gary, your fix took the errors away as well while the data is still flowing as it should for now.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.