public function daysOfWeek($daysOfWeek)
  {
    // Check for empty, string or no value
    if (empty($daysOfWeek) || is_string($daysOfWeek) === false || strlen($daysOfWeek) < 3) {

      // Return with a null parse
      return null;
    }

    // Separate days of the week by comma
    $daysOfWeek = explode(',', $daysOfWeek);

    // Allowed values
    $allowedValues = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];

    // Make sure each day of week
    foreach ($daysOfWeek as $dayOfWeek) {

      // Is an allowed value
      if (in_array($dayOfWeek, $allowedValues) === false) {

        // Otherwise return with a null parse
        return null;
      }
    }

    // Return days of the week
    return $daysOfWeek;
  }
public function daysOfWeek($daysOfWeek)
  {
    // Check for empty, string or no value
    if (empty($daysOfWeek) || is_string($daysOfWeek) === false || strlen($daysOfWeek) < 3) {

      // Return with a null parse
      return null;
    }

    // Separate days of the week by comma
    $daysOfWeek = explode(',', $daysOfWeek);

    // Allowed values
    $allowedValues = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];

    // Make sure each day of week
    foreach ($daysOfWeek as $dayOfWeek) {

      // Is an allowed value
      if (in_array($dayOfWeek, $allowedValues) === false) {

        // Otherwise return with a null parse
        return null;
      }
    }

    // Return days of the week
    return $daysOfWeek;
  }
public function daysOfWeek ( $ daysOfWeek ) { // Check for empty, string or no value if ( empty ( $ daysOfWeek ) || is_string ( $ daysOfWeek ) === false || strlen ( $ daysOfWeek ) < 3 ) { // Return with a null parse return null ; } // Separate days of the week by comma $ daysOfWeek = explode ( ',' , $ daysOfWeek ) ; // Allowed values $ allowedValues = [ 'mon' , 'tue' , 'wed' , 'thu' , 'fri' , 'sat' , 'sun' ] ; // Make sure each day of week foreach ( $ daysOfWeek as $ dayOfWeek ) { // Is an allowed value if ( in_array ( $ dayOfWeek , $ allowedValues ) === false ) { // Otherwise return with a null parse return null ; } } // Return days of the week return $ daysOfWeek ; }
Parses a string like "mon,tue,wed,thu,fri,sat,sun" into a array

@param  string $daysOfWeek     example: mon,tue,wed,thu,fri,sat,sun    mon,wed,fri
@return null|array             null if there was a parsing error or a array with parsed days of the week
Parses a string like mon tue wed thu fri sat sun into a array