Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Location
    Now Southern Oregon. I was born and had lived my life in Los Angeles until relocating last year (2010)
    Posts
    215
    Thanks
    52
    Thanked 1 Time in 1 Post

    multi dimensional arry reference?

    I haven't done this for a while.

    I have OOP code that builds a multidimensional array
    PHP Code:
    // get ready .....
    // test case: 'cat|jewelry:{necklaces_and_pendants,earrings,bracelets,jewery_boxes}:mirrors:tables:unique_gems{figurines,photo_frames,hanging_pieces,lamps}'
    // '$_array is pre exploded test case string around '|'
    private function procItemArry($_array$_return)
                   {
                    
    $this->Lst $_array;
                    
    $this->retVal $_return;
                    
    $this->out = array();
                    
    $this->cats '';
                    
    $this->subCats '';
                    
    $this->subSubCats '';
                    
    $this->test '';
                    for(
    $this->0$this->count($this->Lst); $this->i++)
                       {
                        if(
    strpos($this->Lst[$this->i], ':') > -1)
                          {
                           
    $this->test .= ':';
                           
    $this->out[$this->i] = array();
                           
    $this->out[$this->i] = explode(':'$this->Lst[$this->i]);
                           for(
    $this->0$this->count($this->out[$this->i]); $this->j++)
                              {
                               if(
    strpos($this->out[$this->i][$this->j], '{') > -1// if array item is a group
                                 
    {
                                  
    $this->test .= '{';
                                  
    $this->start strpos($this->out[$this->i][$this->j], '{');
                                  
    $this->length strpos($this->out[$this->i][$this->j], '}') -1;
                                  
    $this->hold substr$this->out[$this->i][$this->j], $this->start$this->length);
                                  
    $this->out[$this->i][$this->j] = explode(','$this->hold);
                                  for(
    $this->0$this->count($this->out[$this->i][$this->j]); $this->k++)
                                     {
                                      
    $this->test .= ',';
                                      
    $this->subSubCats .= '      '.$this->out[$this->i][$this->j][$this->k]."\n";
                                     }
                                  if(
    $this->subSubCats != '')
                                    {
                                     
    $this->subCats .= $this->subSubCats;
                                    }
                                 }
                               else
                                 {
                                  
    $this->test .= "!}";
                                  
    $this->subCats .= '   '.$this->out[$this->i][$this->j]."\n";
                                 }
                              }
                          }
                        else
                          {
                           if(
    $this->subCats == '')
                             {
                              
    $this->test .= "!:";
                              
    $this->cats .= $this->Lst[$this->i]."\n\n";
                             }
                           else
                             {
                              
    $this->cats .= $this->Lst[$this->i]."\n\n".$this->subCats;
                             }
                          }
                       }
                    switch(
    $this->retVal)
                      {
                       case 
    'string':
                       return 
    $this->cats;
                       break;
                       case 
    'test':
                       return 
    $this->test;
                       break;
                       case 
    'array';
                       return 
    $this->out;
                       break;
                       default:
                       return 
    'Second argument unacceptible';
                      }
                   } 
    using the second argument 'test' the output is:
    !::!}{,,,,!}!}{,,,,
    So, I know the conditionals are working
    When I use 'string', all I get is 'cat'
    The Question:
    What is wrong with
    PHP Code:
    $this->out[$this->i][$this->j
    or
    PHP Code:
    $this->out[$this->i][$this->j][$this->k
    ?
    Last edited by anotherJEK; 04-12-2012 at 03:42 AM. Reason: spelling correction

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Location
    Now Southern Oregon. I was born and had lived my life in Los Angeles until relocating last year (2010)
    Posts
    215
    Thanks
    52
    Thanked 1 Time in 1 Post

    Making headway

    For some reason my php doesn't like me using the variable names
    $this->subCat or $this->subSubCat. I revised it so the $this->test
    variable collects the string components and it is working.

    I have run into mysteries of this sort with php on occasion. I guess
    I can congratulate myself for not going crazy over this. But I still have
    lots more work to do.

    Thanks for any time and attention already spent.
    For those just looking for possible solutions to mysterious problems;
    this may help.

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Location
    Now Southern Oregon. I was born and had lived my life in Los Angeles until relocating last year (2010)
    Posts
    215
    Thanks
    52
    Thanked 1 Time in 1 Post

    Here's more

    I finally figured out what was wrong.
    Missing a necessary step in variable assignment.


  •  

    Posting Permissions

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