ConorHolt ConorHolt - 22 days ago 8
PHP Question

Which complexity mb_strlen?

strlen
complexity is O(1), because string structure save string length, but what about
mb_strlen
? And please explain me, why?

Answer

Looking at source code in worst case it is O(N).

mbtab = encoding->mblen_table;
n = 0;
p = string->val;
k = string->len;
/* count */
if (p != NULL) {
    while (n < k) {
        m = mbtab[*p];
        n += m;
        p += m;
        len++;
    };
}