Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6180069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:46:52+00:00 2026-05-24T00:46:52+00:00

I have three numbers: $a = 1 $b = 5 $c = 8 I

  • 0

I have three numbers:

$a = 1
$b = 5
$c = 8

I want to find the minimum and I used the PHP min function for that. In this case it will give 1.

But if there is a negative number, like

$a = - 4
$b = 3
$c = 9

now the PHP min() should give $b and not $a, as I just want to compare positive values, which are $b and $c. I want to ignore the negative number.

Is there any way in PHP? I thought I will check if the value is negative or positive and then use min, but I couldn’t think of a way how I can pass only the positive values to min().

Or should I just see if it’s negative and then make it 0, then do something else?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:46:53+00:00Added an answer on May 24, 2026 at 12:46 am

    You should simply filter our the negative values first.

    This is done easily if you have all of them in an array, e.g.

    $a = - 4;
    $b = 3;
    $c = 9;
    
    $values = array($a, $b, $c);
    $values = array_filter($values, function($v) { return $v >= 0; });
    $min = min($values);
    
    print_r($min);
    

    The above example uses an anonymous function so it only works in PHP >= 5.3, but you can do the same in earlier versions with

    $values = array_filter($values, create_function('$v', 'return $v >= 0;'));
    

    See it in action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of incomplete ordered numbers. I want to find a particular
I have a list of phone numbers with area code prefixes that I want
I have three tables in a MySQL database used in a music library application:
So I have an array of numbers that look something like 1,708,234 2,802,532 11,083,432
Imagine I have two (three, four, whatever) tasks that have to run in parallel.
I have a continuous linear programming problem that involves maximizing a linear function over
I'm working with data that is natively supplied as rational numbers. I have a
I have a list of lists which I want to find the intersection for
What's a good algorithm to solve this problem? I have three groups of people
I have three tables like this CREATE TABLE `money`.`categories` ( `ID` bigint(20) unsigned NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.