Hi Kent!
On Sat, 14 Jul 2001, Kent Sandvik wrote:
>
> > function sum_array( $input_array )
> > {
> > var $index;
> > var $sum = 0;
> >
> > for( $index = 0; $index < count( $input_array ); $index++ )
> > $sum += $input_array[ $index ];
> >
> > return $sum;
> > }
>
> The array variable issue has indeed bitten me a couple of times, so now all
> my arrays are called $<something>_arr. It would nice to introduce more
> runtime checking of array types and complaints in case non-array values are
> used in functions. But otherwise the strong type checking will just cause
> more problems and more overhead with calls. I don't know if the example
> above will help that much, but you could already write similar code in
> functions to make sure that the values are declared on top, to make things
> clearer.
>
you can add:
!is_array($input_array) && ($input_array = array($input_array);
before your for() loop, if the "client" of sum_array() doesn't guarentee to
provide only arrays.
-- teodor
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]