Asistente de Arreglo
El archivo Asistente de Arreglo contiene funciones que asisten al trabajo con arreglos.
Cargando este Asistente
Este asistente es cargado usando el siguiente código:
$this->load->helper('array');
Las siguientes funciones están disponibles:
element()
Le permite traer un item de un arreglo. La función prueba si el índice del arreglo existe y si tiene un valor. Si un valor existe, es devuelto. Si el valor no existe, devuelve FALSE o lo que haya especificado como valor por defecto a través del tercer parámetro. Ejemplo:
$arreglo = array('color' => 'rojo', 'forma' => 'redondo', 'tamaño' => '');
// devuelve "rojo"
echo element('color', $arreglo);
// devuelve NULL
echo element('tamaño', $arreglo, NULL);
random_element()
Toma un arreglo como entrada y devuelve un elemento aleatorio de él. Ejemplo de uso:
$citas = array(
"I find that the harder I work, the more luck I seem to have. - Thomas Jefferson",
"Don't stay in bed, unless you can make money in bed. - George Burns",
"We didn't lose the game; we just ran out of time. - Vince Lombardi",
"If everything seems under control, you're not going fast enough. - Mario Andretti",
"Reality is merely an illusion, albeit a very persistent one. - Albert Einstein",
"Chance favors the prepared mind - Louis Pasteur"
);
echo random_element($citas);