Use php array_map in classes
PHP array_map function can be used to map an array with class methods.
Here is an example:
<?php
class Form{
public function sanitizeData()
{
$data = [
' this is a text with extra spaces ',
'and <strong>this</strong> has too<br>much tags'
];
return array_map(array($this, 'sanitize'), $data);
}
private function sanitize($value)
{
return strip_tags(trim($value));
}
}
$form = new Form();
var_dump($form->sanitizeData());
Written by Marco Cervellin
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#