0
if ( count( $entry_array>0 ) )  
{
    $GLOBALS[ 'year' ] = substr($entry_array[0], 5, 2);     //line 22 
    $GLOBALS[ 'month' ] = substr($entry_array[0], 7, 2);    //line 23     
    $GLOBALS[ 'day' ] = substr($entry_array[0], 9, 2);      //line 24     
}

error at line 22, 23, 24 saying Notice: Undefined offset: 0

Any idea to solve this issue..

1
  • What are you trying to achieve? What is the content of $entry_array? Commented Aug 3, 2015 at 14:03

4 Answers 4

7

The if should read

if (count($entry_array) > 0)

In your code, you are evaluating $entry_array > 0, which would return a boolean. Then you are getting the count of that value, which always usually results in 1 if the argument is not an array.

When evaluating 1 as bool (for the if), it evaluates to true, so eventually you execute the body of the if even if the array is empty.

So then it is not guaranteed to work, since maybe your array doesn't have index 0, but likely this was the cause, so I'd try this first.

Sign up to request clarification or add additional context in comments.

1 Comment

plus1: i was writing the same :D
0
if (count( $entry_array) > 0)   {

//line 22     $GLOBALS[ 'year' ] = substr($entry_array[0], 5, 2);

//line 23     $GLOBALS[ 'month' ] = substr($entry_array[0], 7, 2);

//line 24     $GLOBALS[ 'day' ] = substr($entry_array[0], 9, 2);    }

No proper indentation for the if block.

Comments

0
if(count($entry_array)>0 && isset($entry_array[0]))
{
  //your code

}

Comments

0

Change it to something like this,

if (count($entry_array)>0)  {
     ....
    }

or

 if (is_array($entry_array)&&count($entry_array)>0&&isset($entry_array[0]))  {
      ...
     }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.