沃梦达 / 编程问答 / php问题 / 正文

php中逗号分隔的列表

comma separated list in php(php中逗号分隔的列表)

本文介绍了php中逗号分隔的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个由逗号分隔的列表,它应该看起来像这样(绿色、橙色、红色).

I am trying to build a list separated by commas which should look like this (green, orange, red).

$i=0;
$taxonomy = $form_state[values][taxonomy][5];
foreach ($taxonomy as $key => $value){
  $result = db_query("SQL CODE goes here");
  if (mysql_num_rows($result)){     
  while ($i<mysql_num_rows($result)){
    $resultset = db_fetch_array($result);
    $comma_separated = implode(",", $resultset);
    $i++;      
  }
  form_set_error("Date", t("$comma_separated. cannot be booked more than once "));
}

推荐答案

$resultset=array();
while ($data = db_fetch_array($result)) {
    $resultset[] = $data;
}
$comma_separated = implode(",", $resultset);

这篇关于php中逗号分隔的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:php中逗号分隔的列表

基础教程推荐