1
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);
4
  • 3
    Not reproducible. ideone.com/3ml8C Commented May 30, 2010 at 10:04
  • Same here, works for me (codepad.org/1dXCg7B4) $pages does not even look like an associative array. Commented May 30, 2010 at 10:17
  • "$pages does not even look like an associative array" - how do you mean? Commented May 30, 2010 at 10:26
  • "associative array" is associated with something more like array('foo'=>1, 'bar'=>3). Commented May 30, 2010 at 11:38

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, var_dump of $pages led to me to the solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.