Jump to content

Setting up an array


phpretard

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.