Jump to content

Variable Multidimentional Array


dyluck

Recommended Posts

Hi There.

 

How does one go about creating a variable multidimentional array?

Im building a crawler of sorts.  It will crawl category trees and then follow the links it finds to lower depths.  Of course, I need to keep track of the category name as well and then hopefully when it hits the bottom it has nicely stored the whole thing in parent and child nodes within the array.

 

I been searching high and low for a decent description or example.

 

Really hope someone can help.

 

Link to comment
Share on other sites

Have you checked out the Array page on php.net?

http://php.net/manual/en/language.types.array.php

 

Arrays can contain arrays, so you have true multidimensional arrays. You can also use an integer or a string for a key.

 

print_r is handy for printing an array's contents to the browser, for example, so you can see what's going on with it at any time.

 

Best thing to do is to start creating some arrays and playing with adding and accessing values to them.

 

Hope this helps...

Link to comment
Share on other sites

Trust me, I am the biggest fan of trial and error.  I have scowered the array section of the php manual. 

I just don't know whats happening....

 

here is my code:

 

foreach(catrules($_SESSION['SMID']) as $catrule) {
$querys = "SELECT * FROM CR_SCRAPER_CATSET WHERE CATSETID = $catrule[CATSETID]" ;
$results = mysql_query($querys) or die(mysql_error());
while($pinfos = mysql_fetch_array( $results ))
{  
if($x == 0 ) {
	//initialization of the categories
	$categories =  array(Apple, Orange, Kiwi, Banana, Plum); 
	foreach($categories as $key => $val){  $cats[$z][$key] =  $val; $z++;  }


	}

	if($catrule['DEPTH'] == 3) {
		for($i=2; $i <= $catrule['TYPE']; $i++) {	
		foreach($cats as $cat => $link) {
		$cats[$z][$key] = spliter($pinfos['FDELIM'],$pinfos['SPLIT'],$pinfos['EDELIM'],$pinfos['ESPLIT'],$pinfos['SEPERATOR'],$pinfos['FIRSTNUM'],$pinfos['PATTERN'],$pinfos['LSPLIT'],$pinfos['CSPLIT'],sourceget($link),$link,$catrule['LINKSETTING'],$link,$catrule['URL']);
		$z++;
		} //end for j loop
		}//end for loop catrule 'type'
	}//end if Catrule depth 3

	if($catrule['DEPTH'] == 2) {
		foreach($cats as $cat => $link) {			
		$cats[$z][$cat] = spliter($pinfos['FDELIM'],$pinfos['SPLIT'],$pinfos['EDELIM'],$pinfos['ESPLIT'],$pinfos['SEPERATOR'],$pinfos['FIRSTNUM'],$pinfos['PATTERN'],$pinfos['LSPLIT'],$pinfos['CSPLIT'],sourceget($link),$link,$catrule['LINKSETTING'],$link,$catrule['URL']);

		$z++;
		} //end for j loop
		}//end for loop catrule 'type'
	//}//end if Catrule depth 3

$x++;
}//end catrule while
} // end foreach catrules

traverse($cats);	

 

So, what its supposed to spit out is something like:

 

    * 0 =>

          o Apples => http://www.fruitsite.com/home.php?cat=348

            * 5 =>

                  o Red => http://www.fruitsite.com/home.php?cat=349

                  o Green => http://www.fruitsite.com/home.php?cat=350

                  o Yellow => http://www.fruitsite.com/home.php?cat=356

    * 1 =>

          o Oranges => http://www.fruitsite.com/home.php?cat=622

    * 2 =>

          o Kiwi => http://www.fruitsite.com/home.php?cat=461

    * 3 =>

          o Banana => http://www.fruitsite.com/home.php?cat=268

    * 4 =>

          o Plum => http://www.monergismbooks.com/home.php?cat=250

 

So on and so fourth as it goes deeper and deeper into the links.

 

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.