May I suggest array_slice()
and func_get_args()
to solve your argument problem?
<?php
function checkname($arr, $name) {
foreach (array_slice(func_get_args(), 1) as $name) {
if (strpos($arr, $name) !== false) {
return $name;
}
}
return '';
}
?>
..alternately, to solve it into infinity (or however many array values your memory can handle) why not pass an array, and simply do the following:
<?php
function checkname($arr, $names) {
foreach ($names as $name) {
if (strpos($arr, $name) !== false) {
return $name;
}
}
return '';
}
checkname($arr[$i], array('PDF', 'PSD', 'PNG'));
?>
Note:
Your current code checks for the position of PDF
, PSD
, PNG
etc., anywhere in your name (in uppercase!!), so MYPNG.PHP
would go through fine, and doge.png
would fail.