Use array_map to call a method in class with multiple params
class FileUploader {
/**
* Upload a single or multiple files to specific target.
*
* @param string|array $file
* @param string $target
* @return mixed
*/
public function upload($file, $target)
{
if (is_array($file)) {
return array_map(
[$this, 'uploadSingle'],
$file,
array_fill(0, count($file), $target)
);
}
return $this->uploadSingle($file, $target);
}
/**
* Upload a single file to a specific target.
*
* @param $file
* @param $target
*/
public function uploadSingle($file, $target)
{
// Code to handle the file upload.
}
}
Written by Djamel Eddine Feddad
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#