Any way to assign array $this to other variable?

Well, i’m doing a drop menu for my categories and I’m getting the values of the database from other file, so in the file I’m working I got an array $this with the parent_id categories… but I can’t equal the variable $this to $categori, only concatenate them… and I can only get the first item of the array then, because if the first one is 1 and the second is 2, I’m getting a ‘12’ for the second value…

This works
[php]$categori .= $this->_cate[$i][‘cate’];[/php]

This doesn’t works
[php]$categori = $this->_cate[$i][‘cate’];[/php]

I really need this to work, someone got any idea?

Ok, I got it inserting it directly in the SQL after 3 days trying to do it somehow harder ???

Hi,

I know that $this is a special kind of thing, it refers to the active object, but I don’t see why you couldn’t assign properties of $this to $categori.

From the code I can see that:

[ol][li]$this has an object property named $_cate[/li]
[li]$_cate is supposed to be an array[/li]
[li]You’re looking for element ( another array really ) $_cate[$i][/li]
[li]You want element ‘cate’ out of this element[/li][/ol]

As far as I can see, if the top statement yields result then the bottom one would also.
Just to be sure, print the value of $this->_cate[$i][‘cate’] out and see if it really contains
what you expect it to contain.

It’s pretty much analog to:
[php]
// this works
$a = $a . ‘b’;

// this doesn’t
$a = ‘b’;
[/php]

Anyway,
good luck! :smiley:
O.

The [$i] array you mean is a for loop, _cate is the array that contains the parent_id of the other caterogies, and I need that number 1 by 1, that’s why I was trying to use another variable ($categori) to take 1 by 1 the element ‘cate’… but…

I solved it by using [php]$this->_cate[$i][‘cate’][/php] directly in the SQL sentence and it worked, after 3 days trying to do it with an aux variable :stuck_out_tongue:

Thanks a lot anyway Ojoshiro :slight_smile:
Timii.

Sponsor our Newsletter | Privacy Policy | Terms of Service