Pretty much self-explanatory.
I have a string:
8:4,7:2,...
I need to get the values from this, the length of the string is not defined, it just has this format:
id:quantity,id:quantity,...
The explode() function breaks a string into an array. Note: The "separator" parameter cannot be an empty string.
The explode() function splits a string based on a string delimiter, i.e. it splits the string wherever the delimiter character occurs. This functions returns an array containing the strings formed by splitting the original string.
Answer: Use the JavaScript split() method If you want to explode or split a string from a certain character or separator you can use the JavaScript split() method. The following example will show you how to split a string at each blank space. The returned value will be an array, containing the splitted values.
A built-in function in PHP that splits a string into different strings is known as explode(). The splitting of the string is based on a string delimiter, that is, explode in PHP function splits the string wherever the delimiter element occurs.
use string's split
method to get this:
String[] array = "8:4,7:2".split(",");
if you want to split string to array use split function
String string="8:4,7:2";
String[] array_from_string = string.split(",");
if you want to join array elements to string use join function
String string_from_array = String.join(",", array_from_string);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With