The below are not valid or necessary.
You are also again using echos and I've already explained that you need to use returns and provided you an example. Your problem is not CB Code Field. Your problem is your code. I've already explained that CB Code Field parses your code from a string using an anonymous function. See the below PHP documentation regarding this.
php.net/manual/en/function.create-function.php
I've also commented on other issues in your code in my previous reply, which you did not fix. Again I am not here to analyze and fix your custom code.