- array_values: documentation ( source)
- in_array: documentation ( source)
- array_keys: documentation ( source)
<?php
$acceptFormat = array(
'jpg' => 'image/jpeg',
'jpg' => 'image/jpg',
'png' => 'image/png'
);
$ext ='jpg';
if (!in_array($ext,array_keys($acceptFormat))) {
throw new RuntimeException('Invalid file format.');
}
$mime = 'video/mkv';
if (!in_array($mime,array_values($acceptFormat))) {
throw new RuntimeException('Invalid mime format.');
}