简体   繁体   English

在PHP数组中出现致命错误

[英]Got fatal error in PHP array

$all = array($stu_quiz_1, $stu_quiz_2, $stu_quiz_3);

$length = count($all);

$low = 10;

$lowest = 0;

for($i = 0; $i<$length; $i++){

if($all($i)<= $low){ // line 34

    $lowest = all($i);

}
else{
    continue;
}
return $lowest;
}

I am new at php so please help me to find it. 我是php的新手,请帮助我找到它。 I just want to get lowest value from this code. 我只想从此代码中获取最低价值。 I have three values like $stu_quiz_1 = 20 , and so on ...it shows: 我有三个值,例如$stu_quiz_1 = 20 ,依此类推...它显示:

Fatal error: Function name must be a string in C:\\xampp\\install\\htdocs\\just\\quiz_handle.php on line 34 致命错误:函数名称必须是第34行上C:\\ xampp \\ install \\ htdocs \\ just \\ quiz_handle.php中的字符串

if($all($i)<= $low){ // line 34

$all is not a function so you can't use parentheses. $all不是函数,因此不能使用括号。 You'll have to use square brackets [] to access the array value. 您必须使用方括号[]来访问数组值。

伙计...不是$all($i) ,而是$all[$i]

Assuming your function is called all then your if clause should be called like below 假设您的函数all被调用,那么您的if子句应如下调用

if(all($i)<= $low){ // line 34

Note the missing $ from the beginning, thus the name is a string and not a variable. 请注意,开头缺少$ ,因此名称是一个string而不是一个变量。

This line : 这行:

$lowest = all($i);

Means that you're calling the function all() with $i as a parameter. 意味着您正在使用$ i作为参数调用函数all()。

But you $all is actually an array not a function so to access an element of an array you use [] . 但是$ all实际上是一个数组,而不是一个函数,因此您可以使用[]访问数组的元素。

So you have to change it to : 因此,您必须将其更改为:

$lowest = $all[$i];

First: Change $all($i) to $all[$i] (on line 34) 首先:将$all($i)更改$all($i) $all[$i] (第34行)

Second: Change $lowest = all($i); 第二:更改$lowest = all($i); (below the line 34) with $lowest = $all[$i]; (在第34行以下),其中$lowest = $all[$i]; . In this you were missing a $ sign in front of all and $i was to be kept inside [] because $all is a variable (containing an array). 在这种情况下,您在all前面都缺少$符号,并且$i被保留在[]内部,因为$all是变量(包含数组)。

To simply get highest or lowest values from an array there are some perfectly suited functions built into the core of PHP - namely max and min . 为了简单地从数组中获取最高或最低值,PHP的核心内置了一些非常合适的函数,即maxmin

$all=array( 0,1,23,99,34,838 );

$lowest = min( $all );
$highest= max( $all );

echo $lowest,', ', $highest;
/* output: 0, 838 */

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHP-阵列致命错误 - PHP - Array fatal error PHP / SQL:成功更新数据行但出现 PHP 致命错误 - PHP / SQL: Successful update a data row but got PHP Fatal Error 为什么我出现致命错误/ jQuery加载+ PHP GET - Why i got fatal error / Jquery load + PHP GET 收到错误“PHP 消息:PHP 致命错误:未捕获错误:Class 'MongoClient' not found in /var/www/html/dbtest.php:5 - Got error 'PHP message: PHP Fatal error: Uncaught Error: Class 'MongoClient' not found in /var/www/html/dbtest.php:5 致命错误:[] 运算符不支持 for 循环中 PHP 数组的字符串错误 - Fatal error: [] operator not supported for string error on PHP Array in for loop PHP 7 致命错误:未捕获错误:无法使用字符串偏移量作为数组 - PHP 7 Fatal error: Uncaught Error: Cannot use string offset as an array 在zf2中出现了渲染器致命错误的错误 - got the error of renderer fatal error in zf2 请帮助:PHP致命错误:看起来我们没有XML文档 - Please Help: PHP Fatal error: looks like we got no XML document 用于 php 5.4 的 Redis 出现致命错误 Class &#39;Redis&#39; not found in Windows machine - Redis for php 5.4 got fatal error Class 'Redis' not found in Windows machine 刚刚更新到symfony3.0找不到php致命错误类 - Just updated to symfony3.0 got php fatal error class not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM