Re: convert a string into an array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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!
> 

Do something like this:

$tonames  = (is_array($tonames)  ? $tonames  : array($tonames) );
$toemails = (is_array($toemails) ? $toemails : array($toemails));

-- 
Jim Lucas
NOC Manager
541-323-9113
BendTel, Inc.
http://www.bendtel.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux