vidyashankara Posted June 23, 2006 Share Posted June 23, 2006 I have the following arrays[code]Array( [0] => 2 A1 B1 C1 X [1] => 2 A2 B2 C3 Y [2] => 2 A3 B3 C3 Z [3] => 3 D1 E1 F1 A [4] => 3 D2 E2 F2 B [5] => 3 D3 E3 F3 C [6] => 4 G1 H1 I1 J [7] => 4 G2 H2 I2 K [8] => 4 G3 H3 I3 L )[/code]How do i merge it to output the following?[code]Array( [0] => 2 A1 B1 C1 X A2 B2 C3 Y A3 B3 C3 Z [1] => 3 D1 E1 F1 A D2 E2 F2 B D3 E3 F3 C [2] => 4 G1 H1 I1 J G2 H2 I2 K G3 H3 I3 L }[/code]Is this possible? Please help me out. I was thinking of the following code[code]$count = $array[0];if (!array_unique($count)) {array_merge($array)}[/code]Doesnt work, i dont know how to define the arrays to merge... Link to comment https://forums.phpfreaks.com/topic/12760-merge-arrays/ Share on other sites More sharing options...
zq29 Posted June 26, 2006 Share Posted June 26, 2006 You don't have more than one array there, you have a single array. But to get the result you require, you could probably go about it like so...[code]<?php$array = array("2 A1 B1 C1 X","2 A2 B2 C3 Y","2 A3 B3 C3 Z","3 D1 E1 F1 A","3 D2 E2 F2 B","3 D3 E3 F3 C","4 G1 H1 I1 J","4 G2 H2 I2 K","4 G3 H3 I3 L");$i = 0;$new = array();$tmp = "";foreach($array as $a) { $tmp .= "$a\t"; $i++; if($i%3==0) { $new[] = $tmp; $tmp = ""; }}echo "<pre>"; print_r($new); echo "</pre>";?>[/code]Might need a little tweaking, but it's along the right path. Link to comment https://forums.phpfreaks.com/topic/12760-merge-arrays/#findComment-49669 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.