Linked Questions

53 votes
6 answers
37k views

I have the following functions. WordPress functions, but this is really a PHP question. They sort my $term objects according to the artist_lastname property in each object's metadata. I want to pass a ...
djb's user avatar
  • 6,091
64 votes
1 answer
35k views

I am using array_map function in my php application. I defined the array_map function like this. $ratingID = $this->db->insert_id(); $rated_item_array = array_map(function ($a) { ...
Kanishka Panamaldeniya's user avatar
39 votes
2 answers
14k views

I want to write a function that does some dirty work logging a transaction, but the anonymous function scope does not seem to register the parent scope $db and $value variables. How can I pass the ...
Jake's user avatar
  • 11.5k
9 votes
2 answers
9k views

I want my function to access an outside variable—from its parent function specifically. However, using the global keyword sets too broad a scope; I need to limit it. How do I get this code to spit out ...
JP Lew's user avatar
  • 4,529
10 votes
1 answer
6k views

I'm trying to get counts of array values greater than n. I'm using array_reduce() like so: $arr = range(1,10); echo array_reduce($arr, function ($a, $b) { return ($b > 5) ? ++$a : $a; }); This ...
Ryan's user avatar
  • 15.4k
12 votes
1 answer
4k views

In the following code the callback function passed to wrap_map can't see the argument in the outer function, why? (see code comment for detail) public static function wrap_implode($ar, $wrap, $delim){...
user678070's user avatar
  • 1,423
7 votes
4 answers
1k views

For example I have the following code: function a($param) { function b() { echo $param; } b(); } a("Hello World!"); That throws an E_NOTICE error because $param is of course undefined (in ...
ComFreek's user avatar
  • 29.5k
2 votes
4 answers
3k views

I'm trying to use $variable inside my callback function. I pass it to another function like this: functionName("egTraders_ItemDataBound"), inside that function I assign it to a variable and the call ...
Alexander Beninski's user avatar
4 votes
3 answers
1k views

class myClass { $myVariable = 'myCallback'; function myFunction() { $body = false; $callback = $this->myVariable; function test($handle, $line) { ...
bernedef's user avatar
  • 707
2 votes
1 answer
1k views

I have this function in php (laravel): public static function isUserParticipatesInTournament($tourId, $userId) { var_dump($userId); //dumped $user = User::find($userId); ...
vlio20's user avatar
  • 9,335
-1 votes
1 answer
2k views

I have a Laravel ->each() function inside a loop. I want to be able to get at the loop variables from within the each function. foreach ($stringsArray as $string) { if (!empty($string)...
Jimmery's user avatar
  • 10.2k
4 votes
1 answer
2k views

I am trying to understand Wordpress structure in more details. As advised to me, using global keyword is not a good idea. Here is what I am trying to accomplish: Inside functions.php $affID = '...
Mohit Tripathi's user avatar
2 votes
1 answer
823 views

In the below function, $input['num_opt'] cannot access $input $input = $request->all(); $validator->after(function($validator) { $num_opt = $input['num_opt']; ...
hkguile's user avatar
  • 4,387
3 votes
3 answers
305 views

I'm using a callback function inside an other function and I need to access a variable from this enclosing function but don't know how to do that. Here is an example: function outer($flag) { $...
kayahr's user avatar
  • 22.3k
1 vote
2 answers
1k views

I have used PHP for a very long time, but not really used callbacks very much until quite recently. In the following code, the callback (the example is QueryPath, in case you're wondering, but it ...
Eva's user avatar
  • 5,117

15 30 50 per page