...

View Full Version : multi dimensional arry reference?



anotherJEK
04-12-2012, 03:32 AM
I haven't done this for a while.

I have OOP code that builds a multidimensional array


// get ready .....
// test case: 'cat|jewelry:{necklaces_and_pendants,earrings,bracelets,jewery_boxes}:mirrors:tables:unique_gems{fig urines,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->i = 0; $this->i < 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->j = 0; $this->j < 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->k = 0; $this->k < 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


$this->out[$this->i][$this->j]

or


$this->out[$this->i][$this->j][$this->k]

?

anotherJEK
04-12-2012, 05:52 AM
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.

anotherJEK
04-12-2012, 06:32 AM
I finally figured out what was wrong.
Missing a necessary step in variable assignment.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum