- in_array: documentation ( source)
<?php
Class Ymodulus
{
/**
* This properties is meant to hold a list of new comers
*/
public $newComers;
/**
* This method is meant to determine if a student is in the list of newcomers
*@Param string $newComer | i casted the variable to always return a string.
*@return boolean. true|false. true if name is in list of newComers and false if its not.
*/
public function welcomes(string $newComer)
{
# here i am checking for the user inputed name in the array. Note am using the short form of if / else statement.
return (in_array($newComers, $this->newComer)) ? true : false;
}
}
//Usage
$ymodulus = new Ymodulus();
$ymodulus->newComers =['MizMyColi', 'other New Bie'];
$result = Ymodulus->welcomes('MizMyColi');
echo ($result === true ) ? 'MizMyColi Ymodulus welcomes you too the world of php': 'sorry not yet welcomed by ymodulus';
?>