phpretard Posted February 26, 2011 Share Posted February 26, 2011 I am trying to separate this information by the "-" symbol so that I can insert it. This output would be ideal. Any help today? 105-2-2-3-Cheerleading $value[0] should = 105 $value[1] should= 2 $value[2] should= 2 $value[3] should= 3 $value[4] should= Cheerleading I have tried many approaches and come up with notta 105-Athletics 105-1-Eagle Sports 105-2-Programs 105-2-1-Boys 105-2-1-1-Football 105-2-1-2-Cross Country 105-2-1-3-Golf 105-2-1-4-Basketball 105-2-1-5-Baseball 105-2-1-6-Track 105-2-1-7-Tennis 105-2-2-Girls 105-2-2-1-Volleyball 105-2-2-2-Golf 105-2-2-3-Cheerleading 105-2-2-4-Basketball 105-2-2-5-Softball 105-2-2-6-Track 105-2-2-7-Tennis 105-3-Coaches 105-4-FHSAA 105-5-Game Directions Thank you for looking. Link to comment https://forums.phpfreaks.com/topic/228925-setting-up-an-array/ Share on other sites More sharing options...
Pikachu2000 Posted February 26, 2011 Share Posted February 26, 2011 Did you try explode? <?php $str = '105-2-2-3-Cheerleading'; $array = explode('-', $str); echo '<pre>'; print_r($array); echo '</pre>'; ?> Returns: Array ( [0] => 105 [1] => 2 [2] => 2 [3] => 3 [4] => Cheerleading ) Link to comment https://forums.phpfreaks.com/topic/228925-setting-up-an-array/#findComment-1180008 Share on other sites More sharing options...
phpretard Posted February 26, 2011 Author Share Posted February 26, 2011 I will try that for sure... Will that be good enough to insert into? inset into table (0,1) values([0], [1], ect...) I need that in some find of foreach loop I only have a page of this...how can I grab these separately? 105-Athletics <<-- separate and explode 105-1-Eagle Sports <<-- separate and explode 105-2-Programs <<-- separate and explode 105-2-1-Boys <<-- separate and explode 105-2-1-1-Football <<-- separate and explode 105-2-1-2-Cross Country <<-- separate and explode 105-2-1-3-Golf <<-- separate and explode and so on... I am ultimately trying to echo this (without the $_GET['pg']): <li><a class="active" href="athletics.php#nfc">Athletics</a> <ul class="sub_menu"> <li><a href="page.php?pg=55#nfc">Eagle Sports</a></li> <li><a href="page.php?pg=56#nfc">Programs</a> <ul class="sub_menu"> <li><a href="page.php?pg=57#nfc">Boys</a> <ul class="sub_menu"> <li><a href="page.php?pg=58#nfc">Football</a></li> <li><a href="page.php?pg=59#nfc">Cross Country</a></li> <li><a href="page.php?pg=60#nfc">Golf</a></li> <li><a href="page.php?pg=61#nfc">Basketball</a></li> <li><a href="page.php?pg=62#nfc">Baseball</a></li> <li><a href="page.php?pg=63#nfc">Track</a></li> <li><a href="page.php?pg=64#nfc">Tennis</a></li> </ul> </li> <li><a href="page.php?pg=65#nfc">Girls</a> <ul class="sub_menu"> <li><a href="page.php?pg=66#nfc">Volleyball</a></li> <li><a href="page.php?pg=67#nfc">Golf</a></li> <li><a href="page.php?pg=68#nfc">Cheerleading</a></li> <li><a href="page.php?pg=69#nfc">Basketball</a></li> <li><a href="page.php?pg=70#nfc">Softball</a></li> <li><a href="page.php?pg=71#nfc">Track</a></li> <li><a href="page.php?pg=72#nfc">Tennis</a></li> </ul> </li> </ul> </li> <li><a href="page.php?pg=73#nfc">Coaches</a></li> <li><a href="page.php?pg=74#nfc">FHSAA</a></li> <li><a href="page.php?pg=75#nfc">Game Directions</a></li> </ul> </li> Link to comment https://forums.phpfreaks.com/topic/228925-setting-up-an-array/#findComment-1180012 Share on other sites More sharing options...
phpretard Posted February 26, 2011 Author Share Posted February 26, 2011 This worked: $infosplit=explode("\n", $information); $array=array(); for($i=0; $i<count($infosplit); $i++) { $infosplit[$i]=trim($infosplit[$i]); if(!empty($infosplit[$i])) { $temp=explode("-", $infosplit[$i]); $temp_array=array(0=>$temp[0],1=>null,2=>null,3=>null,4=>$temp[(count($temp)-1)]); for($a=1; $a<(count($temp)-1); $a++) { $temp_array[$a]=$temp[$a]; } $array[]=$temp_array; } } print_r($array); ?> Link to comment https://forums.phpfreaks.com/topic/228925-setting-up-an-array/#findComment-1180017 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.