Trying to create a method which allows only letters and whitespaces and deny everything that contains numbers and special symbols.
so here is the code
class Users{
public $names = array();
public function add($name){
foreach($this->names as $key){
if (preg_match("/[A-Za-z ]/", $key)) {
array_push($this->names,$key);
}else{
unset($key);
}
}
}
}
$users = new Users();
$users->add('Ja1ne');
$users->add('Sara');
$users->add('Chloe');
$users->add(['Marty', '!Taylor', 'D3ndy']);
var_dump($users);
it should output array with:Sara,Chloe,Marty