RE: [PHP] What's wrong with this code please?

2004-02-24 Thread Chris W. Parker
Donpro 
on Tuesday, February 24, 2004 9:52 AM said:

> $emails =
> array("[EMAIL PROTECTED]","[EMAIL PROTECTED]",[EMAIL PROTECTED]);
> $addresses = explode(",",$emails); for ($i=0; $i < count($addresses);
>$i++) { echo $i . ': ' . $addresses[$i] . '';
>if ($i == count($addresses) - 1)
>   $form['recipient'] .= $addresses[$i];
>else
>   $form['recipient'] .= $addresses[$i] . ',';
>}
>echo 'Recipient = ' . $form['recipient'] . '';

why are you exploding an array? $emails is already an array and can
already be accessed via index i.e. $emails[0..n];

and similar to what adam metioned, i don't even know what would happen
when you explode an array so your unexpected results are, well,
expected. ;)

$emails =
array("[EMAIL PROTECTED]","[EMAIL PROTECTED]",[EMAIL PROTECTED]);
$emails_cnt = count($addresses);

for ($i = 0; $i < $emails_cnt; $i++)
{
  echo "$i:{$emails[$i]}";

  if ($i == ($emails_cnt - 1))
  {
$form['recipient'] .= $emails[$i];
  }
  else
  {
$form['recipient'] .= $emails[$i] . ',';
  }
}

echo "Recipient = {$form['recipient']}";


maybe that will work? (untested)


chris.

p.s. from now on don't use the count() function within loops (including
the loop declaration) because it slows things way down (when you count
the same variable over and over). instead do like what i did, count it
ahead of time and then just reference the answer.

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



Re: [PHP] What's wrong with this code please?

2004-02-24 Thread Adam Bregenzer
On Tue, 2004-02-24 at 12:51, Donpro wrote:
> $emails = array("[EMAIL PROTECTED]","[EMAIL PROTECTED]",[EMAIL PROTECTED]);
> $addresses = explode(",",$emails);
> for ($i=0; $i < count($addresses); $i++) {
>echo $i . ': ' . $addresses[$i] . '';
>if ($i == count($addresses) - 1)
>   $form['recipient'] .= $addresses[$i];
>else
>   $form['recipient'] .= $addresses[$i] . ',';
>}
>echo 'Recipient = ' . $form['recipient'] . '';
> 
>  
> The output I am receiving is:
> 0: Array
> Recipient = Array
>  
> Obviously, I want to see the output of each array element as well as the
> final contents of $form['recipient'].

You need to look up how to use explode[1], my guess is you don't want to
use it at all here.  In fact, implode[2] may be exactly what you are
looking for.

Regards,
Adam

[1] http://www.php.net/explode
[2] http://www.php.net/implode

-- 
Adam Bregenzer
[EMAIL PROTECTED]
http://adam.bregenzer.net/

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



RE: [PHP] What's wrong with this code please?

2004-02-24 Thread Sam Masiello

If you want to see the contents of an array, use the print_r function:

http://www.php.net/print_r

HTH!

--Sam



Donpro wrote:
> $emails =
> array("[EMAIL PROTECTED]","[EMAIL PROTECTED]",[EMAIL PROTECTED]);
> $addresses = explode(",",$emails); 
> for ($i=0; $i < count($addresses); $i++) {
>echo $i . ': ' . $addresses[$i] . '';
>if ($i == count($addresses) - 1)
>   $form['recipient'] .= $addresses[$i];
>else
>   $form['recipient'] .= $addresses[$i] . ',';
>}
>echo 'Recipient = ' . $form['recipient'] . '';
> 
> 
> The output I am receiving is:
> 0: Array
> Recipient = Array
> 
> Obviously, I want to see the output of each array element as well as
> the final contents of $form['recipient']. 
> 
> Thanks in advance,
> Don

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



[PHP] What's wrong with this code please?

2004-02-24 Thread Donpro
$emails = array("[EMAIL PROTECTED]","[EMAIL PROTECTED]",[EMAIL PROTECTED]);
$addresses = explode(",",$emails);
for ($i=0; $i < count($addresses); $i++) {
   echo $i . ': ' . $addresses[$i] . '';
   if ($i == count($addresses) - 1)
  $form['recipient'] .= $addresses[$i];
   else
  $form['recipient'] .= $addresses[$i] . ',';
   }
   echo 'Recipient = ' . $form['recipient'] . '';

 
The output I am receiving is:
0: Array
Recipient = Array
 
Obviously, I want to see the output of each array element as well as the
final contents of $form['recipient'].
 
Thanks in advance,
Don

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