dezkit Posted March 29, 2008 Share Posted March 29, 2008 how do i do an array that i dont have to list one by one, but i can list all at once <? $array[0] = "first"; $array[1] = "second"; $array[2] = "third"; $array[3] = "fourth"; echo $array[]; "<br>" ?> or something like that but there is a break after every array Link to comment https://forums.phpfreaks.com/topic/98509-array/ Share on other sites More sharing options...
wildteen88 Posted March 29, 2008 Share Posted March 29, 2008 To populate an array in a single line you can do: $arr = array('item1', 'item2', 'item3', '... etc ... ' ); to display the contents of an array using print_r echo '<pre>' . print_r($arr, true) . '</pre>'; Link to comment https://forums.phpfreaks.com/topic/98509-array/#findComment-504108 Share on other sites More sharing options...
kenrbnsn Posted March 29, 2008 Share Posted March 29, 2008 You can use print_r, implode with echo, or a foreach loop with echo: Using print_r <?php echo '<pre>' . print_r($array,true) . '</pre>'; ?> Using implode: <?php echo implode('<br>',$array) . '<br>'; ?> Using foreach: <?php foreach ($array as $val) echo $val . '<br>'; ?> It really depends on what you're looking to do. Ken Link to comment https://forums.phpfreaks.com/topic/98509-array/#findComment-504110 Share on other sites More sharing options...
dezkit Posted March 29, 2008 Author Share Posted March 29, 2008 <?php echo implode('<br>',$array) . '<br>'; ?> that worked thank you! thank you 2 wildteen! Link to comment https://forums.phpfreaks.com/topic/98509-array/#findComment-504112 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.