Tag Archive for implode

Implode Form Element Array

// implodeFormArray(form name : String, form element name : String, delimiter : String);
function implodeFormArray(f, e, del) {
	var form	= document.forms[f];
	if (typeof(form.elements[e].value) != "undefined") {
		if (form.elements[e].checked) return form.elements[e].value;
		else return '';
	} else {
		var output	= '';
		var len		= form.elements[e].length;
		for(var i=0;i<len;i++) {
			if (form.elements[e][i].checked) {
				output+= (output == '' ? '':del) + form.elements[e][i].value;
			}
		}
		return output;
	}
}

source

Get random item array in PHP

<ul>
<?php
// LI items
$a = array(
"<li>Elemento 1</li>",
"<li>Elemento 2</li>",
"<li>Elemento 3</li>",
"<li>Elemento 4</li>",
"<li>Elemento 5</li>",
"<li>Elemento 6</li>",
"<li>Elemento 7</li>",
"<li>Elemento 8</li>",
"<li>Elemento 9</li>"
);
shuffle( $a );
$na = array_slice( $a, 0, 4 );
echo implode('', $na );
?>
</ul>

source