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..
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.
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.
if(count($entry_array)>0 && isset($entry_array[0]))
{
//your code
}
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])) {
...
}