0

I want to upgrade my server's PHP from 5.5 to 7, as I heard it will perform faster.

I read in the documentation that:

list() can no longer unpack string variables. str_split() should be used instead.

Currently I have a string quantity variable which contains a string of comma seperated numbers, like 2,5,3.

I'm using list in order to create 3 new variables, one per each of these 3 comma separated values:

list($item[$key + 1]["red"], $item[$key + 1]["green"], $item[$key + 1]["blue"]) = explode(",", $item[$key + 1]["quantity"]);

Will this command no longer work on PHP 7? If so, how should I write it with str_split?

rockyraw
  • 1,125
  • 2
  • 15
  • 36

1 Answers1

0

You may use explode to accomplish what you are trying to do.

$quantity = '2,5,3';
$item = explode(',',$quantity);
print_r($item);
Dave
  • 5,108
  • 16
  • 30
  • 40
  • I'm working with multiple arrays and using a loop. I can't fit it into a single command. – rockyraw Apr 23 '18 at 11:51
  • You didn't say that in your original question. Can you be more specific about what your requirements are? You should be able to take the array values after the explode and assign them as you need to. – Dave Apr 23 '18 at 11:53