my problem is a bit similar to some existing topic like this 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"