简体   繁体   English

简单的PHP警告问题?

[英]Simple PHP warning question?

I was wondering how can I correct this warning I keep getting listed below. 我想知道如何纠正此警告,但我会继续在下面列出。

I'm using PHP & MySQL 我正在使用PHP和MySQL

Warning: min() [function.min]: Array must contain at least one element

Here is part of the code I think is causing the problem. 这是我认为引起问题的部分代码。

$tags = tag_info($link);

$minimum_count = min(array_values($tags));
$maximum_count = max(array_values($tags));
$spread = $maximum_count - $minimum_count;

I would of posted the whole code but some ignorant users will probably feel its a duplicate question so if you need to see the full code please look at the past questions thanks. 我会发布整个代码,但是一些无知的用户可能会觉得它是一个重复的问题,因此,如果您需要查看完整的代码,请查看过去的问题,谢谢。

Okay I'm thinking its not this piece of code because every ones code is not displaying anything but its getting rid of the warning. 好的,我认为这不是这段代码,因为每个代码都不会显示任何内容,而是摆脱了警告。 You can see the full code here Full code 您可以在此处看到完整的代码完整的代码

$tags = tag_info($link);

$spread = $tags ? max($tags) -  min($tags) : 0;

That code is valid as long as your tag_info() function returns an array. 只要您的tag_info()函数返回一个数组,该代码就有效。

PHP's built-in array_values() function is useless, since min() and max() both ignore the keys in an array. PHP的内置array_values()函数是无用的,因为min()和max()都忽略了数组中的键。

if( !empty( $tags ) )
    {
      $minimum_count = min( array_values( $tags ) ) ;
    }
$tags = tag_info($link);

if ( 
  is_array( $tags ) &&
  count( $tags ) > 0
) {
  $values = array_values( $tags );

  $spread = max( $values ) - min( $values );
} else
  $spread = 0;

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM