我的代码应该通过大写每个单词的第一个字母来固定课程的名称。然后,我需要在globals数组中对它们进行排序,并与它们一起打印出一条消息。我认为我已经正确地完成了所有这些操作,但是当我尝试仅打印出变量时,我的浏览器中什么也没得到,也没有错误消息出现。我想知道如何在数组中打印这些更改的变量。
<?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'];
?>
答案 0 :(得分:1)
您遇到语法错误- print_r
是一个函数;您想传递$GLOBALS['CIS475']
作为参数。
将print_r $GLOBALS['CIS475']
替换为print_r($GLOBALS['CIS475'])
,您的代码将按预期工作。
可以在 here 上看到它。
答案 1 :(得分:-2)
<?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']);
?>