hamza Posted March 8, 2010 Share Posted March 8, 2010 1_1 1_2 3_5 i have this is in $_POST array i want to separate this string by using _ separate. kindly separate the values 1 and 1 from 1_1 or same as like that.others thanks Link to comment https://forums.phpfreaks.com/topic/194521-string-separation/ Share on other sites More sharing options...
sasa Posted March 8, 2010 Share Posted March 8, 2010 look http://php.net/manual/en/function.explode.php Link to comment https://forums.phpfreaks.com/topic/194521-string-separation/#findComment-1023096 Share on other sites More sharing options...
Anti-Moronic Posted March 8, 2010 Share Posted March 8, 2010 Yeh, use explode(): $string = '1_1'; $str2arr = explode('_', $string); print_r($str2arr); Link to comment https://forums.phpfreaks.com/topic/194521-string-separation/#findComment-1023100 Share on other sites More sharing options...
hamza Posted March 8, 2010 Author Share Posted March 8, 2010 $string = array('1_1','1_2','2_3'); $str2arr = explode('_', $string); using this concept how i use explode Link to comment https://forums.phpfreaks.com/topic/194521-string-separation/#findComment-1023123 Share on other sites More sharing options...
Anti-Moronic Posted March 8, 2010 Share Posted March 8, 2010 $string = array('1_1','1_2','2_3'); $str2arr = explode('_', $string); using this concept how i use explode Thought you might have wanted that..that's quite simple too. You just loop through the initial array and explode each item: $string = array('1_1','1_2','2_3'); foreach($string as $val){ $arr[] = explode('_', $val); } print_r($arr); Then if you want to access the first num in the first item, you use: $arr[0][0]; // first num in first item $arr[0][1]; // second num in first item Hope that helps. Link to comment https://forums.phpfreaks.com/topic/194521-string-separation/#findComment-1023126 Share on other sites More sharing options...
hamza Posted March 12, 2010 Author Share Posted March 12, 2010 thanks Link to comment https://forums.phpfreaks.com/topic/194521-string-separation/#findComment-1025352 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.