0

While working i met this annoying message

Strict Standards: Only variables should be passed by reference in G:\xampp\htdocs\MyProject\ZendSkeletonApplication\module\Admission\src\Admission\Controller\AdmissionController.php on line 107

My code

$consoldatedCities='';

array_walk_recursive($StateCityHash, function($cityName,$cityId) use(&$consoldatedCities){$consoldatedCities[$cityId] = $cityName; }); // line 107

This is to convert multidimensional array into simple array

But the code works as i expected.. can anyone tell me how to solve this problem

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
vimal1083
  • 8,499
  • 6
  • 34
  • 50
  • possible duplicate of [Strict Standards: Only variables should be passed by reference](http://stackoverflow.com/questions/2354609/strict-standards-only-variables-should-be-passed-by-reference) – Lorenz Meyer Jun 21 '14 at 08:15

1 Answers1

0

Here http://php.net/manual/en/language.references.pass.php it says that "There is no reference sign on a function call - only on function definitions." Try removing the '&' from your function call code there and see if that gets rid of the message.

---Edit---

Looking at this thread here "Strict Standards: Only variables should be passed by reference" error

you could try saving your callback function into a variable before passing it to the array walk function:

$consoldatedCities=array();

$callbackFcn= 
   function($cityName,$cityId) use(&$consoldatedCities)
   {
      $consoldatedCities[$cityId] = $cityName; 
   };

array_walk_recursive($StateCityHash, $callbackFcn);
Community
  • 1
  • 1
Anna T
  • 956
  • 1
  • 9
  • 20
  • Thanks for your immediate response. If i remove the '&' from function call the '$consoldatedCities' will be empty – vimal1083 Aug 13 '13 at 05:51
  • Thanks,Still I am getting the same error in this line `array_walk_recursive($StateCityHash, $callbackFcn);` . here we have just assigned the same function in `$callbackFcn`, so it also causing same error.I think that i have to revert and to do something with `foreach`. – vimal1083 Aug 14 '13 at 17:09