note 91839 deleted from function.range by danbrown

From: Date: Sun, 28 Jun 2009 05:15:53 +0000
Subject: note 91839 deleted from function.range by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157639@lists.php.net to get a copy of this message
Note Submitter: chads2k2 at yahoo dot com ---- Hey all, I found a problem that I was having with making columns for Excel 2007. They want them in the format A, B, C, D, AA, AB, AC, AD, ect The only one I found was a question like this on Experts Exchange, which I never liked so I am posting the free version on how to create like I just listed. It goes from A->ZZZ <?php // Set the field names $fieldCols = array(); $level1 = range("A","Z"); foreach($level1 as $tmp_lvl) { array_push($fieldCols,$tmp_lvl); } foreach($level1 as $tmp_level1) { foreach($level1 as $tmp_level2) { array_push($fieldCols,$tmp_level1 . $tmp_level2); } } foreach($level1 as $tmp_level1) { foreach($level1 as $tmp_level2) { foreach($level1 as $tmp_level3) { array_push($fieldCols,$tmp_level1 . $tmp_level2 . $tmp_level3); } } } echo "<pre>"; print_r($fieldCols); echo "</pre>"; /* Shows: Array( [0] = A [1] = B [2] = C [3] = D ... [26] = AA [27] = AB [28] = AC [29] = AD ... [257] = IX [258] = IY [259] = IZ ... [702] = AAA [703] = AAB [704] = AAC [705] = AAD ... [18275] = ZZX [18276] = ZZY [18277] = ZZZ ) */ ?> Of course, you could put that into a function and make the code a lot cleaner, but it shows you what to do. Use it for whatever you would like. I am using it to help do data functions on my wife's dissertation.

« previous php.notes (#157639) next »