dpepbjp126917 2010-05-30 09:55
浏览 27
已采纳

关联数组上的php max()和min()

print_r($pages);
print max($pages);
print min($pages);

shows me

Array ( [0] => 1 [1] => 2 [2] => 3 ) 1 2 

While I was expecting the last two numbers to be 3 and 1. How come?

EDIT: further info

$pages = $v->plaintext;
var_dump($pages);
$exp = explode("|", $pages);
print_r($exp);
print max($exp);

gives

string(324) " 1 | 2 | 3 " Array ( [0] => 1 [1] => 2 [2] => 3 ) 1 

Not sure what the "string(324) is? It's still outputting "1" as the max($exp) ...

EDIT: found solution, I was dealing with strings. This now works and prints out 3.

$pages = $v->plaintext;                 
$exp = explode("|", $pages);
$exp = array_map("trim", $exp);
$exp = array_map("intval", $exp);
print max($exp);
  • 写回答

1条回答 默认 最新

  • dounianluo0086 2010-05-30 10:04
    关注

    The following works for me.

    $a=array(1,2,3);
    
    print_r($a);
    print max($a);
    print min($a);
    

    You'll need to dump more debug info for your $pages var to dig more.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度