Schlo_50 Posted February 14, 2008 Share Posted February 14, 2008 Hey guys, I am pulling information from a text file, which i then want to display on my webpage in a row. I want to label each value as a number one to five and then loop around again. So for example: 1.'value' 2.'value'3.'value' 4.'value'5.'value' 1.'value' 2.'value' 3.'value' I can get the values from the text file fine and display them on a page but i cannot figure out how to count the values and make sure the first is '1.' and second is '2.' etc. Maybe i need some kind of array? asort? This is how i am getting the files: $lines = file("file.txt"); foreach ($lines as $line) { $data[$key] = explode("|", $line); $value = trim($data[$key][1]); $a = "1."; $b = "2."; $c = "3."; $d = "4."; $e = "5."; print $catname; Any help would be great, however if you need more questions do feel free to ask! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/91036-array-of-values/ Share on other sites More sharing options...
PHP Monkeh Posted February 14, 2008 Share Posted February 14, 2008 How are the values stored in your text file? I can see an explode on | but it would help us out Just there could be one per line, or all on one line etc. Quote Link to comment https://forums.phpfreaks.com/topic/91036-array-of-values/#findComment-466609 Share on other sites More sharing options...
Psycho Posted February 14, 2008 Share Posted February 14, 2008 Something like this: <?php $lines = file("file.txt"); $no = 1; foreach ($lines as $line) { $data[$key] = explode("|", $line); $value = $no . ". " . trim($data[$key][1]); print $value; $no = ($no==5) ? 1 : $no+1 ; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/91036-array-of-values/#findComment-466613 Share on other sites More sharing options...
Schlo_50 Posted February 14, 2008 Author Share Posted February 14, 2008 One per line. Quote Link to comment https://forums.phpfreaks.com/topic/91036-array-of-values/#findComment-466614 Share on other sites More sharing options...
Schlo_50 Posted February 14, 2008 Author Share Posted February 14, 2008 Thanks mjdamato, Could I sub this variable '$no = 1;' for anything i liked? Say the word One for example? Quote Link to comment https://forums.phpfreaks.com/topic/91036-array-of-values/#findComment-466621 Share on other sites More sharing options...
Psycho Posted February 14, 2008 Share Posted February 14, 2008 You can do whatever you want with it. Of course if you are wantingthe textual values of 'one, two, three, four' you will need to add some more functionality to transpose the numbers to their textual representations. Quote Link to comment https://forums.phpfreaks.com/topic/91036-array-of-values/#findComment-466799 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.