Question: my problem is a bit similar to some existing topic like [this](https://stackoverflow.com/questions/1028668/get-first-key-in-a-possibly-associative-array)
but the solution didn't fit to my problem.
I have an array in function, I want to return the index :

```
protected function commonUploadErrors($key)
    {
         $uploadErrors = array(
                UPLOAD_ERR_INI_SIZE     => "File is larger than the specified amount set by the server",
                UPLOAD_ERR_FORM_SIZE    => "File is larger than the specified amount specified by browser",
                UPLOAD_ERR_PARTIAL      => "File could not be fully uploaded. Please try again later",
                UPLOAD_ERR_NO_FILE      => "File is not found",
                UPLOAD_ERR_NO_TMP_DIR   => "Can't write to disk, due to server configuration ( No tmp dir found )",
                UPLOAD_ERR_CANT_WRITE   => "Failed to write file to disk. Please check you file permissions",
                UPLOAD_ERR_EXTENSION    => "A PHP extension has halted this file upload process"
            );

            return $uploadErrors[$key];
        }

```

If **key = 3** I want to return `UPLOAD_ERR_NO_FILE` and not `"File is not found"`,
I tried return `key($uploadErrors[$key]);` and return `index_keys$uploadErrors[$key];` but didn't work

I used 

```
$result = array_keys($uploadErrors);
     return $result[$key];

```

and I return "3" as well, I think it is the real value of the reserved error code UPLOAD\_ERR\_NO\_FILE. So I want to return the name of the code not its value, when I echo UPLOAD\_ERR\_FORM\_SIZE , I get "2"

Answer: 
Your `$uploadErrors` contains constants for the keys, so it will not have the name of the constants as keys, but their values [as indicated in the PHP Manual](http://php.net/manual/en/features.file-upload.errors.php), e.g.

```
$uploadErrors = [
    UPLOAD_ERR_INI_SIZE => "foo", 
    UPLOAD_ERR_FORM_SIZE => "bar", 
    …
]

```

will result in this array:

```
[1 => "foo", 2 => "bar", …]

```

Since the `UPLOAD_ERR_` constants are Core constants, you can get them programmatically and then map their values to the names, e.g. something like this:

```
foreach (get_defined_constants(true)['Core'] as $name => $value) {
    if (strpos($name, 'UPLOAD_ERR_') === 0) {
        $uploadErrorMap[$value] = $name;
    }
}

echo $uploadErrorMap[array_keys($uploadErrors)[3]];

```

This will then output `"UPLOAD_ERR_NO_FILE"` as a string. 

See this demo: <https://eval.in/367710>

If you want your `$uploadErrors` to contain the actual constant *names*, put them into quotes, [as shown here](https://stackoverflow.com/a/30349215/208809).

---

**Reference:** 

* [`get_defined_constants` — Returns an associative array with the names of all the constants and their values](http://php.net/get_defined_constants)
* [`strpos` — Find the position of the first occurrence of a substring in a string](http://php.net/strpos)
* [`array_keys` — Return all the keys or a subset of the keys of an array](http://php.net/array_keys)
* [General reference on Arrays](http://php.net/manual/en/language.types.array.php)
Try the following:

```
var_dump(array_slice($input, 3, 1));

```