while($row2=mysql_fetch_array($result2)){ $key[] = $row2['NOMPDTO']; } echo 'var collection = ["' . implode('", "', $key) . '"];'; ?>