That's a nice iterative solution. One small correction: the for loop should start at 0, rather than 1, because it may need to create the very first directory in the path.
(I tested it with my_mkdir('dir1/dir2/dir3', '0777'); it worked only if dir1 already existed.)