asmith Posted October 30, 2009 Share Posted October 30, 2009 Hi, I need to pass a variable to my sort function for usort (or uksort) function cmp($a, $b, $myVariable) How do i pass $myvariable through usort? usort($theArray, "cmp") is there an special syntax I'm missing? Quote Link to comment https://forums.phpfreaks.com/topic/179612-passing-another-variable-to-usort/ Share on other sites More sharing options...
Mchl Posted October 30, 2009 Share Posted October 30, 2009 I'm afraid usort does not support such thing. Quote Link to comment https://forums.phpfreaks.com/topic/179612-passing-another-variable-to-usort/#findComment-947714 Share on other sites More sharing options...
asmith Posted October 30, 2009 Author Share Posted October 30, 2009 so my only way is passing the array with global? Quote Link to comment https://forums.phpfreaks.com/topic/179612-passing-another-variable-to-usort/#findComment-947727 Share on other sites More sharing options...
Daniel0 Posted October 30, 2009 Share Posted October 30, 2009 Create another function. Possibly an anonymous function or using create_function if you're using <PHP 5.3. Quote Link to comment https://forums.phpfreaks.com/topic/179612-passing-another-variable-to-usort/#findComment-947732 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.