array_keys

Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Return all the keys or a subset of the keys of an array
<?php array_keys(array $array): array
<?php         assert(isset($data['defects']) && is_array($data['defects']));

        assert(isset($data['times']) && is_array($data['times']));



        foreach (array_keys($data['defects']) as $test) {

            $data['defects'][$test] = TestStatus::from($data['defects'][$test]);

        }
<?php             "A test with the description '%s' has %d argument(s) ([%s]) and no dataset(s) provided in %s",

            $name,

            count($arguments),

            implode(', ', array_map(static fn (string $arg, string $type): string => sprintf('%s $%s', $type, $arg), array_keys($arguments), $arguments)),

            $file,

        ));

    }
<?php         foreach ($keys as $k => $key) {

            try {

                if (is_array($key)) {

                    $this->toHaveKeys(array_keys(Arr::dot($key, $k.'.')));

                } else {

                    $this->original->toHaveKey($key);

                }
<?php     {

        foreach ($keys as $k => $key) {

            if (is_array($key)) {

                $this->toHaveKeys(array_keys(Arr::dot($key, $k.'.')), $message);

            } else {

                $this->toHaveKey($key, message: $message);

            }
<?php         }, ARRAY_FILTER_USE_KEY);



        $closestScopeDatasetKey = array_reduce(

            array_keys($matchingDatasets),

            fn (string|int|null $keyA, string|int|null $keyB): string|int|null => $keyA !== null && strlen((string) $keyA) > strlen((string) $keyB) ? $keyA : $keyB

        );
<?php             '# Object \(…\)#' => '',

        ];



        return (string) preg_replace(array_keys($map), array_values($map), $this->exporter->shortenedExport($value));

    }

}
<?php         $dirtyFiles = array_map(

            fn (string $file, string $status): string => in_array($status, ['R', 'RM'], true)

                ? explode(' -> ', $file)[1]

                : $file, array_keys($dirtyFiles), $dirtyFiles,

        );



        $dirtyFiles = array_filter(
<?php use Pest\Repositories\DatasetsRepository;



it('show only the names of named datasets in their description', function () {

    $descriptions = array_keys(DatasetsRepository::resolve([

        [

            'one' => [1],

            'two' => [[2]],

        ],

    ], __FILE__));



    expect($descriptions[0])->toBe('dataset "one"')

        ->and($descriptions[1])->toBe('dataset "two"');
<?php });



it('show the actual dataset of non-named datasets in their description', function () {

    $descriptions = array_keys(DatasetsRepository::resolve([

        [

            [1],

            [[2]],

        ],

    ], __FILE__));



    expect($descriptions[0])->toBe('(1)');

    expect($descriptions[1])->toBe('([2])');
<?php });



it('show only the names of multiple named datasets in their description', function () {

    $descriptions = array_keys(DatasetsRepository::resolve([

        [

            'one' => [1],

            'two' => [[2]],

        ],

        [

            'three' => [3],

            'four' => [[4]],

        ],

    ], __FILE__));



    expect($descriptions[0])->toBe('dataset "one" / dataset "three"');

    expect($descriptions[1])->toBe('dataset "one" / dataset "four"');
<?php });



it('show the actual dataset of multiple non-named datasets in their description', function () {

    $descriptions = array_keys(DatasetsRepository::resolve([

        [

            [1],

            [[2]],

        ],

        [

            [3],

            [[4]],

        ],

    ], __FILE__));



    expect($descriptions[0])->toBe('(1) / (3)');

    expect($descriptions[1])->toBe('(1) / ([4])');
<?php });



it('show the correct description for mixed named and not-named datasets', function () {

    $descriptions = array_keys(DatasetsRepository::resolve([

        [

            'one' => [1],

            [[2]],

        ],

        [

            [3],

            'four' => [[4]],

        ],

    ], __FILE__));



    expect($descriptions[0])->toBe('dataset "one" / (3)');

    expect($descriptions[1])->toBe('dataset "one" / dataset "four"');
<?php });



it('shows the correct description for long texts with newlines', function () {

    $descriptions = array_keys(DatasetsRepository::resolve([

        [

            ['some very \nlong text with \n     newlines'],

        ],

    ], __FILE__));



    expect($descriptions[0])->toBe('(\'some very long text with …wlines\')');

});
<?php });



it('shows the correct description for arrays with many elements', function () {

    $descriptions = array_keys(DatasetsRepository::resolve([

        [

            [[1, 2, 3, 4, 5]],

        ],

    ], __FILE__));



    expect($descriptions[0])->toBe('([1, 2, 3, …])');

});
<?php });



it('shows the correct description of datasets with html', function () {

    $descriptions = array_keys(DatasetsRepository::resolve([

        [

            '<div class="flex items-center"></div>',

        ],

    ], __FILE__));



    expect($descriptions[0])->toBe('(\'<div class="flex items-center"></div>\')');

});