Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/206059-array_map-for-non-array-variable/
Share on other sites

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.

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.