(all) for the best

used to say that something will have a good result even though it was not the intended result