list to array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

list to array

Post by gurjit »

hi all,

i have a list like this

1,2,3,4,5

i want to take each item in the list and display in number format on a new line....for example

1.00
2.00
3.00
4.00
5.00

how can i do this?
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

Hi,

Code: Select all

<?php
	$numbers = "1,2,3,4,5,6";
	$number_array = explode(',', $numbers);
	foreach ($number_array as $number)
	{
		echo number_format($number, 2, '.', '') . "<br>";
	}
?>
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

Post by gurjit »

thanks launchcode, worked great. one of those days for me.

many thanks. have a great day.
Post Reply