0

I currently am getting the following error message when splitting out array values by character: Strict Standards: Only variables should be passed by reference

This is my array:

array(6) { [0]=> string(8) "2390:SS0" [1]=> string(8) "2391:SS1" [2]=> string(9) "2392:SS11" [3]=> string(7) "250:BS1" [4]=> string(8) "251:BS10" [5]=> string(8) "252:BS11" }

This is my php:

foreach ($postcodes as $key => $value)
{
  $postcode_ids     = current(explode(':', $value));
  $postcode         = next(explode(':', $value));
}

The notice seems to appear on the next line? Any ideas or pointer would be great. Thanks.

Jonas
  • 121,568
  • 97
  • 310
  • 388
neoszion
  • 249
  • 2
  • 11
  • 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:35

1 Answers1

1

next() modifies the array that you pass in. It is passed by reference. Therefore you cannot use

next( [expression] );

but only

next( [variable] );

To simplify your code, replace

 $postcode_ids     = current(explode(':', $value));
 $postcode         = next(explode(':', $value));

with

 list($postcode_ids, $postcode) = explode(':', $value);
Lorenz Meyer
  • 19,166
  • 22
  • 75
  • 121