Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Vince Mendella
Vince Mendella
6,480 Points

php script on new line on Mac OSX using Sublime Text 2?

I am doing the PHP Arrays and Control Structures course and am putting in the code exactly as on the video. I can't get the output to be on separate lines: <?php $task1 = array( 'title' => 'Laundry', 'priority' => 2, 'due' => '', 'complete' => true, ); $task2 = array( 'title' => 'Clean out refrigerator', 'priority' => 3, 'due' => '07/30/2017', 'complete' => false, ); $list = array($task1,$task2); var_dump($list); ?>

I get the output all on the same line. How do I do this on the Mac? I have tried \n, \r but nothing works.

3 Answers

It's probably trying to render html so you can try

echo "<br />\n";

This should display the output on seperate lines. If you're viewing the code via a console the \n should work fine.

Vince Mendella
Vince Mendella
6,480 Points

Thank you. That's what I thought but wanted to see if it could be done without echoing out the <br /> tag. I tried it in the code and just got a white screen. Here is the code I tried.

<?php $list[] = [ 'title' => 'Laundry' 'priority' => 2, 'due' => '', 'complete' => true, ]; $list[] = [ 'title' => 'Clean out refrigerator', 'priority' => 3, 'due' => '07/30/2017', 'complete' => false, ]; var_dump($list); //echo $list[0]['title']; ?>

I have taken php in a night course (over my head at the time) and was trying it then to no avail and still can't get it to work on the Mac.

Well the var_dump will just display the array in a line. All you're echo'ing there is the first item in the list. If you wanted to echo each of them on a new row you'd have to use a for loop to loop through the array and list each one.

for ($list as $item) {
  echo $item['title'] . "<br />";

Again it depends if you're outputting to console or a web browser. \n should work fine if it's console.

I think theres something in the php.ini that makes var_dump display with html, not sure if I'm remembering that right or not. ini_set("html_errors", 1); perhaps?

Could always wrap the var_dump in echo "<pre>"; var_dump($list); echo "</pre>";