Hi guys,
There is something that I often wonder about the way to use custom functions :
When the output of a function is used for a condition and for a result at the same time, how do you make it so that the function is run only once?
I mean, in the example below, is there a way to produce the same result but with hd_file_format_check run only once?
Thanks !
There is something that I often wonder about the way to use custom functions :
When the output of a function is used for a condition and for a result at the same time, how do you make it so that the function is run only once?
I mean, in the example below, is there a way to produce the same result but with hd_file_format_check run only once?
Thanks !
Code:
function hd_file_format_check($file_type, $ok_types) {
$types_array = explode("|", $ok_types);
$result = false;
for ($k = 0; $k < sizeof($types_array); $k++) {
if (strstr($file_type, $types_array[$k])) {
$result = "." . str_replace("jpeg", "jpg", $types_array[$k]);
}
}
return $result;
}
--------------------------
..
if(hd_file_format_check($_FILES["form_prod_pic"]["type"][$key], "gif|jpeg|jpg") != false) {
$file_ext = hd_file_format_check($_FILES["form_prod_pic"]["type"][$key], "gif|jpeg|jpg");
// do other things here ...
}
..