johnsmith153 Posted May 26, 2009 Share Posted May 26, 2009 I want to do this: $value = "23**44**22**97**46**65"; list($a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8, $a9, $a10, $a11, $a12, $a13, $a14, $a15 ) = explode("**",$value); $array[]=$a1; $array[]=$a2; $array[]=$a3; //etc... But there is obviously a better way. Also, there could be one or hundreds of values seperated by the **. (**1**2**3...109**110**111 etc.) Surely this would be the best method (if it was possible): $value = "23**44**22**97**46**65"; list( convert to $array ) = explode("**",$value); What is the best way? Link to comment https://forums.phpfreaks.com/topic/159784-really-simple-list-array-explode/ Share on other sites More sharing options...
lonewolf217 Posted May 26, 2009 Share Posted May 26, 2009 simply using <?php $list = explode("**",$value); will get you what you want. you do not have to predefine the number of array elements prior to the explode. you can then access the elements either like <?php echo $list[0]; echo $list[1]; //or foreach($list as $element) { echo $element; } If this is not what you were looking for, try to explain in more detail Link to comment https://forums.phpfreaks.com/topic/159784-really-simple-list-array-explode/#findComment-842746 Share on other sites More sharing options...
Cosizzle Posted May 26, 2009 Share Posted May 26, 2009 Im sorry i miss understand here. But do you want all those values in multiple arrays? so for every "**" break that value will be put into an array? I wrote this. It works the same as lonewolf $a4 = explode("**",$value); echo '<pre>'; print_r($a4); echo '</pre>'; Link to comment https://forums.phpfreaks.com/topic/159784-really-simple-list-array-explode/#findComment-842749 Share on other sites More sharing options...
johnsmith153 Posted May 26, 2009 Author Share Posted May 26, 2009 $list = explode("**",$value); is exactly what I need. Thanks. Link to comment https://forums.phpfreaks.com/topic/159784-really-simple-list-array-explode/#findComment-842751 Share on other sites More sharing options...
lonewolf217 Posted May 26, 2009 Share Posted May 26, 2009 cool, dont forget to mark the topic solved Link to comment https://forums.phpfreaks.com/topic/159784-really-simple-list-array-explode/#findComment-842754 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.