Re: Question about 'sizeof'
SM wrote:
> Hello,
> I have another simple question about an array in PHP and a variable in
> PHP.
>
> This is the array:
>
> $thumbs_cat_1 = array(
> 'wine',
> 'cheese',
> 'ice',
> 'bread'
> );
>
>
> $thumbs_cat_2 = array(
> 'hello',
> 'goodbye'
> );
>
>
> This will work:
> $item_total = sizeof($thumbs_cat_1);
> output: 4
>
> $item_total = sizeof($thumbs_cat_2);
> output: 2
>
>
> Now, i want to replace the parameter in 'sizeof' by a variable
>
> $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
best regards
Piotr N
|