Re: working on array of different number of indices

From: Date: Wed, 16 May 2001 16:56:32 +0000
Subject: Re: working on array of different number of indices
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-53065@lists.php.net to get a copy of this message
On Wed, 16 May 2001, Dennis Gearon wrote: > I want to pass in a scalar int, or an array of ints (indices) to a > function in a class. The scalar or array will be a class variable. > > Without knowing the max size of each index, or the number of indices, > (as is required is most other languages), I can't figure out how to > access the array in a flexible fashion. What I **WANT** to use as a > clue is whether the passed $index value is a scalar, or how many > elements are in the array. > > examples: > > function work_on_array( $value, $index ){ > blah to $this->value_s_holder; > .. > .. > } > > work_on_array( 7, array(4,5) ); > work_on_array( 23, 1 ); > > The number of INDICES will not change during program execution, although > I do not want to have to predict the range of the scalar/indices. > > any ideas? I am having trouble parsing this question. Are you simply asking if there is away to check whether the $index parameter is a scalar or an array? If so, see php.net/gettype -Rasmus

« previous php.general (#53065) next »