Help with formatting array data

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
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Help with formatting array data

Post by mhouldridge »

Hi,

I have array data which I need to format. Currently the output looks like this;

[0] => 192.168.241.1
[1] => 192.168.241.2
[2] => 192.168.241.3
[3] => 192.168.241.5
[4] => 192.168.241.7

and my script to output this is as follows;

Code: Select all

echo'<pre>';
print_r($available_ips); 
echo '</pre>'
Is there anyway to html format this or to simply take out the "[0] =>" part so that the IPs are the only thing shown?

thanks in advance
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

print_r() is intended more as a debug function, not for presentation.

To get the actual details you need use a foreach loop. For example....

Code: Select all

foreach($available_ips as $value) {
    echo $value.'<br />';
}
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post by mhouldridge »

ah,

Thankyou!
Post Reply