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

PHP

Kris Byrum
Kris Byrum
32,636 Points

Help with PHP Array(); in Resume

I'm having troubles getting my PHP Array(); to show for my online resume.

I'm attempting to make a copy of my resume on my portfolio page for employers to review, but my experience won't show.

Could someone please take a second look and let me know what they think the problem is? I've gone through the simple PHP program and double check it on that as much as possible.

Thanks in advance.

Main Resume HTML markup page ---

<?php 
include("jobs.php"); 
include("inc/header.php");
?>

<section>
<?php foreach($jobs as $job){
    echo employer_list_view($job);
}; 
?>
</section>

My jobs.php page (I've reduce the amount of items and changed some of the content to keep things simple here.)

<?php
function employer_list_view($job) {
    $output = "";
    $output = $output . "<h3>" . $job["employer"] . "</h3>";
    $output = $output . "<h3>" . $job["title"] . "</h3>";
    $output = $output . "<h3>" . $job["city"] . "</h3>";
    $output = $output . "<ul>";
    $output = $output . "<li>" . $job["first"] . "</li>";
    $output = $output . "<li>" . $job["second"] . "</li>";
    $output = $output . "<li>" . $job["third"] . "</li>";
    $output = $output . "</ul>";
};


$jobs = array();
$jobs[101] = array(
    "employer" => "Freelance Web Developer",
    "title" => "Web Developer // Owner",
    "city" => "Seattle, WA",
    "first" => "Plan, design, develop, and test websites utilizing various programming languages based on the specific job at hand.",
    "second" => "nothing here yet",
    "third" => "nothing here also"
    );
$jobs[102] = array(
    "employer" => "Better Business Bureau",
    "title" => "Investigator",
    "city" => "Seattle, WA",
    "first" => "Regularly conducted analysis of BBB policies...",
    "second" => "Drafted public alerts....",
    "third" => "Handled incoming ...."
);

2 Answers

Hi Kris,

One problem that I see is that you're trying to echo out the return value from your function but it doesn't return the $output variable.

You probably need return $output; at the end of your employer_list_view function.

Kris Byrum
Kris Byrum
32,636 Points

YOU are my hero.

So basically I added return $output to the end of my function and then added the key/value syntax ($jobs as $job_id => $job) to the foreach and then added the $job_id to the function and it worked.... Guess I didn't try everything!!!

Thanks for those second pair of eyes Jason!

code fix for others who need help:

<?php foreach($jobs as $job_id => $job){
    echo employer_list_view($job_id, $job);
}; 
?>

function employer_list_view($job_id, $job) {
    $output = "";
    $output = $output . "<h3>" . $job["employer"] . "</h3>";
    $output = $output . "<h3>" . $job["title"] . "</h3>";
    $output = $output . "<h3>" . $job["city"] . "</h3>";
    $output = $output . "<ul>";
    $output = $output . "<li>" . $job["first"] . "</li>";
    $output = $output . "<li>" . $job["second"] . "</li>";
    $output = $output . "<li>" . $job["third"] . "</li>";
    $output = $output . "</ul>";

    return $output;
};

$jobs = array();
$jobs[101] = array(.....