phparraysprintingsuperglobals

Unable to print items from an array in php


My code is supposed to fix the name of the courses by capitalizing the first letter of each word. Then I need to sort them in the globals array and print out a message with them. I think I have done all of that correctly but when I try to even print out just the variable I get nothing in my browser and no error messages to go off either. I'm wondering how I can print these changed variables in the array.

<?php
$course1 = "advanced web development";
$course2 = "mobile app development";
$course3 = "info systems with business intell";

function fixCourseName($courseName)
{
$courseName = ucwords($courseName);
return $courseName;
}

$GLOBALS['CIS475'] = fixCourseName ($course1);
$GLOBALS['CIS360'] = fixCourseName ($course2);
$GLOBALS['CIS429'] = fixCourseName ($course3);

print_r $GLOBALS['CIS475'];

?>

Solution

  • <?php
    $course1 = "advanced web development";
    $course2 = "mobile app development";
    $course3 = "info systems with business intell";
    
    function fixCourseName($courseName)
    {
    $courseName = ucwords($courseName);
    return $courseName;
    }
    
    $GLOBALS['CIS475'] = fixCourseName ($course1);
    $GLOBALS['CIS360'] = fixCourseName ($course2);
    $GLOBALS['CIS429'] = fixCourseName ($course3);
    
    print_r($GLOBALS['CIS475']);
    
    ?>