开发者_JAVA技巧im trying to print an array using implode, but i want to tweak it, so the "glue" of the implode show every two element, and not in every element.
$nombreNombre=array('josh','13','mike','44','dude','98','scott','450');
echo '<li>' . implode('</li><li>', $nombreNombre).'</li>
with that im getting:
and i want:
You could run $nombreNombre
through array_chunk
, do an array_map
to convert each pair to a string, then implode
.
$arr = array('josh','13','mike','44','dude','98','scott','450');
$arr = array_chunk($arr, 2);
function repr($pair) { list($a, $b) = $pair; return "$a $b"; }
$arr = array_map("repr", $arr);
echo '<li>' . implode('</li><li>', $arr) . '</li>';
精彩评论