Re: Question about 'sizeof'
On May 8, 11:15 am, SM <servandomont...@gmail.com> 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?
>
> Thanks
> Marco
Marco,
You should be getting a return of 1 (integer) for a string passed to
the count() function. (sizeof is an alias of count)
To get the length of a string, you would traditionally use
strlen($item), which would return the length of a string.
Regards,
Steve
|