My array lenght is 7.
However if I want to print the content at any index I get this error message:
Notice: Undefined offset: 0 (or 1, or 2, or 3..)
Is it maybe because it is declared, but not initialized ?
thanks
how to know the not empty indexes of an array ?
Moderator: General Moderators
Re: how to know the not empty indexes of an array ?
Array keys don't have to be numbers, and they don't have to start at zero if they are.
If you want to get rid of the keys and number everything starting at zero use array_values.
Code: Select all
print_r(array(
5 => 'five',
'string' => "string for a key",
-13 => "a negative number"
));Re: how to know the not empty indexes of an array ?
If you don't need to use the numbers for anything then consider using a foreach loop
Code: Select all
foreach($array as $key => $val){
//Do yo thang
}Re: how to know the not empty indexes of an array ?
I don't know the keys. I just want to know if myArray[0] is empty or not. myArray[1].. is empty or not..
I need to know where the values are stored..
I need to know where the values are stored..
Re: how to know the not empty indexes of an array ?
empty? More like isset.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: how to know the not empty indexes of an array ?
array_keys($yourArray)aneuryzma wrote:I don't know the keys. I just want to know if myArray[0] is empty or not. myArray[1].. is empty or not..
I need to know where the values are stored..