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.

1

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

2 Comments

Im not sure how I would split the value of the array, if I can use next?
Fantastic, works great. I have never seen this array function before it will come in very handy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.