$data = array("1" => "James Stewart", "2" => "Gary Cooper", "3" => "James Cagney");
$jsontext = "[";
foreach($data as $key => $value) {
$jsontext .= "{valor: '".addslashes($key)."', texto: '".addslashes($value)."'},";
}
$jsontext = substr_replace($jsontext, '', -1); // quitar la última coma
$jsontext .= "]";

No hay comentarios:
Publicar un comentario