1- Por medio de json_decode()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// String json de un array asociativa | |
define('FORM_ARRAY_JSON_MODELOS_SEXO','{"m":"Masculino","f":"Femenino"}'); | |
// Generamos el array con el string que esta en la constante | |
var_dump( json_decode(FORM_ARRAY_JSON_MODELOS_SEXO,TRUE) ); | |
//echo $this->Form->input('sexo', array('type'=>'select', 'options'=> json_decode(FORM_ARRAY_JSON_MODELOS_SEXO,TRUE))); |
2- Por medio de eval(), var_export()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Array asociativa | |
define('FORM_ARRAY_JSON_MODELOS_SEXO', 'return ' . var_export(array('m'=>'Masculino','f'=>'Femenino'), 1) . ';'); | |
// Generamos el array con el string que esta en la constante | |
var_dump( eval(FORM_ARRAY_JSON_MODELOS_SEXO) ); | |
//echo $this->Form->input('sexo', array('type'=>'select', 'options'=>eval(FORM_ARRAY_JSON_MODELOS_SEXO))); |
3- Por medio serialize() y unserialize()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Array asociativa | |
define('FORM_ARRAY_MODELOS_SEXO', serialize(array('m'=>"Masculino",'f'=>"Femenino")) ); | |
// Generamos el array con el string que esta en la constante | |
var_dump( unserialize(FORM_ARRAY_MODELOS_SEXO) ); | |
//echo $this->Form->input('sexo', array('type'=>'select', 'options'=>unserialize(FORM_ARRAY_MODELOS_SEXO))); |
Para mi gusto por seguridad y simpleza la opción 1 o 3 son las mejores de implementar dentro de codigo PHP.
No hay comentarios:
Publicar un comentario