Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback function in loops doesn't work #493

Closed
kledo-34 opened this issue Dec 12, 2020 · 1 comment
Closed

Callback function in loops doesn't work #493

kledo-34 opened this issue Dec 12, 2020 · 1 comment

Comments

@kledo-34
Copy link

kledo-34 commented Dec 12, 2020

Hey there,
not sure if this is a bug, but I tried the following without success:

$array = [['columnName', 'two'],['columnName2','two2']];
foreach ($array as $x) {
	$this->my_variable = $x; 
	$crud->callback_column($x[0], function ($fieldValue) {					
		return $x[1]; });
};

For the first Loop this works, but on all other loops it seems like conflicting with overwriting each other or something, I really don't clearly understand what is goin on there, as the result is not logic anymore. Some values get completely added to a wrong column and some are not introduced at all.
I would be happy about any help.
Thank you very much :)

@kledo-34
Copy link
Author

kledo-34 commented Dec 12, 2020

Fellaz, I got it, please spread this across the groceryCRUD forums aswell as I was not able to find this solution there, it was not even provided by the admins. The suggestion was always to use $this->variable or a session, but there is something easier, which works for those anonymous functions. You can pass as many variables to the function as you want to by the use statement, reference here: Anonymous Functions

function ($requiredParams) use ($yourvar1, $ yourvar2, etc.) {
   ....};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant