SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard
    Join Date
    Apr 2000
    Posts
    1,483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey all,

    Hope someone is able to help me out here
    As suggested by the title, I'm using a 4 dimensional array to hold category information (hierarchially). I know the right data is in the right places in the array because I can do a print_r($array) statement and it shows it correctly.
    But here is the dilemma:

    I'm using a pair of loops to get down to the fourth level in the array:
    PHP Code:
      while ( list($key1,$val1)=each($cache["$categoryid"]) ) {
        while ( list(
    $key2,$category)=each($val1) ) { 
    And it just isn't working. No errors, warnings etc. Anything placed after that first while() statement just doesn't execute. Just above that I have:
    PHP Code:
    print_r($cache[$categoryid]); 
    which works fine and produces this:
    PHP Code:
    Array
    (
        [
    1] => Array
            (
                [
    0] => 1
                
    [catid] => 1
                
    [1] => Advertising Services
                
    [name] => Advertising Services
                
    [2] => 0
                
    [parent] => 0
                
    [3] => Advertising Services
                
    [description] => Advertising Services
                
    [4] => 189
                
    [visits] => 189
                
    [5] => 0
                
    [hide] => 0
            
    )


    which is exactly as it should be.

    I've been coding all day now so it's probably something silly but I'm getting desperate any help is extremely appreciated.

    Thanks in advance
    P.S. In case you're wondering what on earth this has to do with recursive functions, it is being used in a recursive function
    Last edited by James; Apr 28, 2001 at 21:51.

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    The only way the second while loop will fail to execute is if there are no elements in the array $vall. Did you check to see if the variables are the same:

    val1 <=> vall

    If I take those two variables and put them in EditPlus it gives me:

    PHP Code:
    val1 vall
    Can you tell them apart?
    Last edited by 7stud; Apr 28, 2001 at 22:38.

  3. #3
    SitePoint Wizard
    Join Date
    Apr 2000
    Posts
    1,483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm only using a $val1 variable - not $vall.
    Both while() statements are just using $val1.
    I also tried it with an empty variable and it came up with an error about not being an array, which confuses me even more. Surely that means that the variables I'm using are arrays also?

    Thanks for your help much appreciated.

  4. #4
    SitePoint Wizard
    Join Date
    Apr 2000
    Posts
    1,483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I managed to rewrite the function in such a way that it doesn't need 4-d arrays (it is now over 5 times longer but that's beside the point ). Thanks for your help anyway

  5. #5
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just on a broader design issue - James, did you think about designing a Class to encapsulate that data structure? I know that my brain is incapable of conceptualising a four dimensional array

  6. #6
    SitePoint Wizard
    Join Date
    Apr 2000
    Posts
    1,483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol so is mine, that's why my method above failed
    No I didn't think about doing a class for it, and looking back it might have been a good idea. Though for now I'm happy because it works and is fairly efficient If I ever redevelop that function (not likely for a while ) then I'll see about doing a class.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •