开发者

php max() and min() on associative array

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开发者_JS百科 " 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);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜