redcore Posted June 28, 2010 Share Posted June 28, 2010 Hello everyone! I have a unique problem. Basically my ultimate goal is to be able to apply functions in a similar way array_map() does but without having to be in an array. Confusing right? So instead of calling a function like... do_something($var); I'd like to do this... unknown_function($var, 'do_something'); Does so-called "unknown_function" exist? Or can you just not call a function in this way for non-arrays? Sorry if this is confusing! Thanks for any help! Quote Link to comment https://forums.phpfreaks.com/topic/206059-array_map-for-non-array-variable/ Share on other sites More sharing options...
trq Posted June 28, 2010 Share Posted June 28, 2010 Its easy enough to make. function do_something($var) { echo "This is $var within do_something()"; } function call($arg, $callback) { if (function_exists($callback)) { $callback($arg); } } call('Hello', 'do_something'); I'm kinda missing the point though. There are likely better ways to approach this if you tell us what your actually trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/206059-array_map-for-non-array-variable/#findComment-1078170 Share on other sites More sharing options...
redcore Posted June 28, 2010 Author Share Posted June 28, 2010 Yeah, it's sort of odd, I guess. I pass a string of field names ("tableA, tableB, tableC") to a query builder that returns the result in an array (automated). The downside is that is there's no opportunity to modify the resulting data, like converting MySQL datetime to PHP time() or something. My goal is to pass functions with the field names to modify any particular field I want. If you know a better way than this, that'd be great to hear Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/206059-array_map-for-non-array-variable/#findComment-1078196 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.