Re: Re: convert a string into an array

From: Date: Sat, 03 Apr 2010 02:10:46 +0000
Subject: Re: Re: convert a string into an array
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-303763@lists.php.net to get a copy of this message
On 04/03/10 04:56, Nathan Rixham wrote:
Andre Polykanine wrote:
Hello everyone, It's quite simple but I'm still stuck. What I need is the following: I have an array as a parameter of my custom function. However, I'd like to allow users to enter a string instead of an array. In this case (if the parameter is a string), it must be replaced with an array containing only one item - actually, that string. What I'm doing gives me (presumably) errors; function Send ($tonames, $toemails, $subject, $message) { ... if ((!is_array($tonames)) || (!is_array($toemails))) { $tonames[]=$tonames; $toemails[]=$toemails; } I can't give the new array a new name since I address it further in a loop as my function's parameter... hope you understand what I'm saying) Thanks!
function send( $tonames , $toemails , $subject , $message ) { $tonames = (array)$tonames; $toemails = (array)$toemails; } type juggling is a wonderful thing ;)
Yeah this i the best. It will allow the users to enter a string or an array without affecting processing of your function. -- Nilesh Govindarajan Site & Server Administrator www.itech7.com मेरा भारत महान ! मम भारत: महत्तम भवतु !

« previous php.general (#303763) next »