I have an each loop function, i want to return an array outside the function.
//tried defining the array result outside the function, but whenever i printed the array it returning a empty array.
$test->each(function()){
//tried defining the array result inside the function, but whenever i printed the array its returning a undefined array.
$result[] = "test";
}
echo json_encode($result);
//print array Undefined variable: result
EDIT: i think when you use a closure in PHP, the variable inside the function is isolated. i need to convert it into foreach function.