note 91839 added to function.range

From: Date: Sun, 28 Jun 2009 01:17:23 +0000
Subject: note 91839 added to function.range
Groups: php.notes 
Request: Send a blank email to php-notes+get-157635@lists.php.net to get a copy of this message
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. ---- Server IP: 64.71.164.2 Probable Submitter: 71.60.61.76 ---- Manual Page -- http://www.php.net/manual/en/function.range.php Edit -- https://master.php.net/note/edit/91839 Del: integrated -- https://master.php.net/note/delete/91839/integrated Del: useless -- https://master.php.net/note/delete/91839/useless Del: bad code -- https://master.php.net/note/delete/91839/bad+code Del: spam -- https://master.php.net/note/delete/91839/spam Del: non-english -- https://master.php.net/note/delete/91839/non-english Del: in docs -- https://master.php.net/note/delete/91839/in+docs Del: other reasons-- https://master.php.net/note/delete/91839 Reject -- https://master.php.net/note/reject/91839 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#157635) next »