Select every first array value in associative array

I dynamically create this associative file array through a PHP script, and now I am wondering how do I select all values inside the root array? I'll explain here in code.

This is the array that is currently getting generated everytime:

Array
(
    [HTML] => Array
        (
            [0] => Index.php
        )

[Javascript] => Array
    (
        [0] => Javascript.js
        [1] => Jquery.js
    )

[0] => New Text Document.txt
[Scripts] => Array
    (
        [0] => Get_Server_files.Script.php
    )

[Style] => Array
    (
        [0] => General.css
        [1] => Menu.css
        [2] => Style.css
    )

[images] => Array
    (
        [WelcomeImages] => Array
            (
                [0] => WelcomeImage0.png
                [1] => WelcomeImage1.png
                [2] => WelcomeImage2.png
                [3] => WelcomeImage3.png
                [4] => WelcomeImage4.png
                [5] => WelcomeImage5.png
                [6] => WelcomeImage6.png
            )

        [0] => bg.jpg
    )

)

From here, how do I select every first value? As in selecting

  • HTML
  • Javascript
  • Scripts
  • Style
  • Images.

And not anything that is inside these arrays.

I have searched but everytime it's not quite what I would like.

Answers


You can use array_keys() to get the names and then use array_filter() to remove the 0 values:

$names = array_filter(array_keys($data));
print_r($names);

Output:

Array
(
    [0] => HTML
    [1] => Javascript
    [3] => Scripts
    [4] => Style
    [5] => images
)

Demo.


Use array_keys()

$keys = array_keys($array);

Need Your Help

Zend_Navigation overwrite with array?

zend-framework zend-navigation

I currently use zend_navigation via an XML file.

QT keyPressedEvent too slow?

c++ performance qt qgraphicsscene

I'm developing a shoot'em up with qt creator and my problem is the link with the keyPressEvent function of my scene: