如果我發佈了問題,請用戶諷刺性地評論,這是因爲我無法做到。PHP - 通過索引獲取數組的所有值的本地函數
我需要知道,如果有一個本地的PHP函數,可以讓我得到一個數組的所有值,指定索引的方式,而不自行車,例如
我有這個數組列表中功能:
function get_mime($index)
{
$data = array(
'jpg' => 'image/jpeg',
'png' => 'image/png',
'gif' => 'image/gif',
'zip' => 'application/x-compressed',
'doc' => 'application/msword',
'dot' => 'application/msword',
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
'docm' => 'application/vnd.ms-word.document.macroEnabled.12',
'dotm' => 'application/vnd.ms-word.template.macroEnabled.12',
'xls' => 'application/vnd.ms-excel',
'xlt' => 'application/vnd.ms-excel',
'xla' => 'application/vnd.ms-excel',
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12',
'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12',
'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
'ppt' => 'application/vnd.ms-powerpoint',
'pot' => 'application/vnd.ms-powerpoint',
'pps' => 'application/vnd.ms-powerpoint',
'ppa' => 'application/vnd.ms-powerpoint',
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12'
);
return $data;
}
,我需要調用這個函數:
get_mime(array('jpg', 'png', 'gif'));
並返回與值的數組:
array('image/jpeg', 'image/png', 'image/gif')
重要:我想用一個本地的PHP函數來做到這一點,而無需使用週期。
非常感謝您的幫助。
您是否嘗試過閱讀,我ponted你的功能呢? – splash58
如果我發表了要求的出版物,諷刺性地評論用戶,這是因爲我做不到。 –
1)爲什麼。 2)你認爲「原生」函數不執行循環嗎? –