无法从 php 中的数组中打印项目
Unable to print items from an array in php
我的代码应该通过将每个单词的首字母大写来固定课程名称。然后我需要在全局数组中对它们进行排序并打印出一条消息。我想我已经正确地完成了所有这些,但是当我什至尝试打印出变量时,我在浏览器中什么也得不到,也没有错误消息消失。我想知道如何在数组中打印这些更改的变量。
<?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'];
?>
您有一个语法错误 -- print_r
是一个函数;你想传递 $GLOBALS['CIS475']
作为参数。
将 print_r $GLOBALS['CIS475']
替换为 print_r($GLOBALS['CIS475'])
,您的代码将按预期工作。
这可以看出有效here.
<?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']);
?>
我的代码应该通过将每个单词的首字母大写来固定课程名称。然后我需要在全局数组中对它们进行排序并打印出一条消息。我想我已经正确地完成了所有这些,但是当我什至尝试打印出变量时,我在浏览器中什么也得不到,也没有错误消息消失。我想知道如何在数组中打印这些更改的变量。
<?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'];
?>
您有一个语法错误 -- print_r
是一个函数;你想传递 $GLOBALS['CIS475']
作为参数。
将 print_r $GLOBALS['CIS475']
替换为 print_r($GLOBALS['CIS475'])
,您的代码将按预期工作。
这可以看出有效here.
<?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']);
?>