1

I am using below php functions to get highest and lowest integer value from my array.

min($output[$k]) AND max($output[$k])

Problem: I want to get maximum and minimum integer values from that array excluding ZEROs and NULL values

2 Answers 2

7

Use array_diff() to filter array:

<?php
header('Content-Type: text/plain');

$buffer   = array(null, 0, 1, 2, 3, 0, null, 1);
$filtered = array_diff($buffer, array(null, 0));

$max = max($filtered);
$min = min($filtered);

var_dump($max, $min);
?>

Shows:

int(3)
int(1)
Sign up to request clarification or add additional context in comments.

Comments

1

Use

max(array_filter($output[$k));

Comments

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.