When I do a print_r of an array, I get this.

Array
(
    [0] => Array
        (
            [0] => 9
        )

[2] => Array
    (
        [0] => 1
        [1] => 3
    )

[3] => Array
    (
        [0] => 2
        [1] => 6
        [2] => 8
    )

[4] => Array
    (
        [0] => 4
        [1] => 5
    )

[7] => Array
    (
        [0] => 7
    )

)

meaning that elements 1,5,7,8,9,10,11,12 are empty. Is there anyway I can 'see' or know they are empty? Because I am store all these elements where the uppermost elements (0 upto 12) refer to groups and now have to print out the members of each group ( or 0 members as the case may be). Is there anyway to see which arrays are empty?

    when you create the array of arrays, if you use the array() function, like so...

    $array = array();
    
    $array[0] = array();
    $array[0] = $arrayinarray
    $array[1] = array();
    
    

    then when you do a print_r of the array it will still appear to be there but as an empty array,

    then what you should do is look through the array

    foreach ($array as $key => $a){
    
    if(empty($a)) echo $key . " is empty";
    
    }
    

    I never checked my syntax or anything but that should start you off

      Not showing up in the print_r() output means that those elements are not set, as opposed to set with an empty value (zero-length array, boolean FALSE, empty string "", etc.). Therefore, they do not exist in the array at all. I suppose you could do something like a for loop through the possible index values and use array_key_exists() to see if each is in the array, but I have a feeling there's a more elegant solution, depending on what it is you are actually trying to do.

        Oh, okay. I thought they were created still and just nothing was inside of it. I'll have to check back for each key using a for loop then, I take it the empty and count approach wouldn't work.

          Write a Reply...