Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_php thread: A List of Variables


Message #1 by Paul <paul@d...> on Thu, 13 Jun 2002 11:08:12 -0400
> Oops.  It's actually the modified implode statement that make it work,
> not the curly brackets.
>
> Is there something better than implode?

Implode() and explode() (and join() and split(), respectively) are created
specifically for converting back and forth between an array and a string.
Since there's two calls to implode required (one for the keys, one for the
values), I'd prefer to do things in a foreach loop (which guarantees that
both strings are truly parallel) and for me is a little more readable.

foreach($data_array as $colname => $value)
{
   $cols .= ',' . $colname;
   $vals .= ',' . $value;
}

$cols = substr($cols, 1); // strip leading comma
$vals = substr($vals, 1); // again


use whatever you like.  I think that implode() runs a lot faster, but I
haven't tested the output to make sure that all cases are handled properly.

take care,

nik


  Return to Index