def phase_folding(t, y, yerr, period):
    """
    phase_folding() allows the phase folding (duh...) of a given data
    accordingly to a given period
    
    Parameters
    ----------
    t: array
        Time array
    y: array
        Measurements array
    yerr: array
        Measurement errors arrays
    period: float
        Period to fold the data
    
    Returns
    -------
    phase: array
        Phase
    folded_y: array
        Sorted measurments according to the phase
    folded_yerr: array
        Sorted errors according to the phase
    """
    foldtimes = t / period
    foldtimes = foldtimes % 1
    if yerr is None:
        yerr = 0 * y
    phase, folded_y, folded_yerr = zip(*sorted(zip(foldtimes, y, yerr)))
    return phase, folded_y, folded_yerr
