[thelist] Dynamic if statement in PHP

Daniel Kushner thelist at websapp.com
Tue Oct 22 12:32:01 CDT 2002


If you have an array : $arr =  array(true, true, true);

Something like this should work:


function validateArray($arr, $index = 0) {
	return $index >= count($arr) ?
		true :
		$arr[$index] && validateArray($arr, ++$index);
}


$value = validateArray($arr);


(didn't test it though)



Regards,
Daniel Kushner
_________________________________________
Need hosting? http://thehostingcompany.us





> -----Original Message-----
> From: thelist-admin at lists.evolt.org
> [mailto:thelist-admin at lists.evolt.org]On Behalf Of Gustavo Arizpe
> Sent: Tuesday, October 22, 2002 1:21 PM
> To: thelist at lists.evolt.org
> Subject: [thelist] Dynamic if statement in PHP
>
>
> Hi all!
>
> I'm struggling with the creatio of what I believe should be called
> "dynamic if statement" in php. I don't know if such thing exists.
>
> I have a query string that might have several variables, say from one to
> five, not always the same variables, and not always the same number of
> variables.
>
> I've managed to put the variable names and values in an array, and I'm
> able to generate the conditions depending on the variables I have.
>
> However I cannot modify the if statment depending on the variables I have.
>
> For example if my query string has two variables I want to perform an if
> statment similar to this:
>
> if ( condition1 AND condition2)
>
> but if the query string has three variables, then the if statement should
> look like this:
>
> if ( condition1 AND conditio2 AND condition3)
>
> I've tried using switch(), case, but it apparently doesn't like it.
>
> Any suggestions?
>
> Thanks a lot in advance.
>
>
> Gustavo Arizpe
> http://www.area.com.mx/estrategica
>
> --
> For unsubscribe and other options, including
> the Tip Harvester and archive of thelist go to:
> http://lists.evolt.org Workers of the Web, evolt !




More information about the thelist mailing list