I am studying PHP and i am trying to understand about callback functions, I really looked around at the manual, At stackoverflow and more websites, And i really dont understand what is PHP CallBack Function , If can some one can please help me understand about this functions, I am looking for simple explanation/guide thank you all and have a nice day.
Share
Take a look at Wikipedia – Callback
It’s a function what you pass to your method or some other function, so it can be called later during that method – function execution.
For example you have callback
beforeSaveand you want do some logic before saving data to database file etc.. (in one place – DRY). You add logic intobeforeSavecallback and this callback being called before data saved.Same is with function on manual for example
array_filter($input, callback)it requires that you pass some function to be executed with $input data.For ex. pass anonymous function:
Will return to you all odd array values, you can change logic in anonymous function to what you want, but
array_filterinternal mechanic will be always the same (iterator algo)