View Single Post

  #7 (permalink)  
Old 05-08-2008
SM
 
Posts: n/a
Default Re: Question about 'sizeof'

On May 8, 11:42 am, Piotr <s...@poczta.onet.pl> wrote:
> >> $thumb = 1;
> >> $item = '$thumbs_cat_' . $thumb; //this outputs a string:
> >> $thumbs_cat_1

>
> >> $item_total = sizeof($item);
> >> output: Nothing!

>
> >> How do i pass a variable to the 'sizeof' function?

>
> > You should use variable variable:
> > $item_total = sizeof($$item);

>
> > Mark double $$
> > This is true in any situation, not only with sizeof

>
> Forgot about one small detail:
> $item = 'thumbs_cat_' . $thumb; //this outputs a string:
> ---------^ loose the '$';
>
> best regards
> Piotr N


I don't need the length of the string , just the actual variable. But
i did like the fact that sizeof is an alias of count. So i will use
count instead.
I didn't know about the $$ tip. Wow! so easy. Thanks, It Works!

Heres the final code:

$thumb = 1;
$item = 'thumbs_cat_' . $thumb;
$item_total = count($item);

Thanks again
Marco
Reply With Quote