Bonjour à tous et merci d'avance pour votre aide.
Je souhaiterais diviser un array en 3.
Cela fonctionne partiellement, quand le array source compte un total impaire de valeurs, il manque toujours un enregistrement lors du traitement.
Merci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 $arrayCount = count($arraySource); if (($arrayCount % 2) == 1) {$arrayCount++;} $arraySlice[0] = array_slice($arraySource, 0, $arrayCount/3); $arraySlice[1] = array_slice($arraySource, $arrayCount/3, $arrayCount/3); $arraySlice[2] = array_slice($arraySource, ($arrayCount/3)*2); $$id = "<h2>{$label}</h2>"; $$id .= "<hr />"; $$id .= '<table width="100%" border="1" cellpadding="0" cellspacing="0">'; $$id .= '<tr><td valign="top" width="33%">'; $$id .= "<ul>".implode("\n", array_map(function($p) { return "<li>{$p}</li>"; }, $arraySlice[2]))."</ul>"; $$id .= '</td><td valign="top" width="33%">'; $$id .= "<ul>".implode("\n", array_map(function($p) { return "<li>{$p}</li>"; }, $arraySlice[1]))."</ul>"; $$id .= '</td><td valign="top" width="33%">'; $$id .= "<ul>".implode("\n", array_map(function($p) { return "<li>{$p}</li>"; }, $arraySlice[0]))."</ul>"; $$id .= "</td></tr></table>"; $$id .= "<br />";
Partager