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 8462607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:12:43+00:00 2026-06-10T14:12:43+00:00

If an array initialized as: $arr = array(array(141,151,161),2,3,array(101,102,array(303,404,606,555,789,array(1000,22,9999,array(9057,100000),522)))); Then the result should be: 100000

  • 0

If an array initialized as:

   $arr = array(array(141,151,161),2,3,array(101,102,array(303,404,606,555,789,array(1000,22,9999,array(9057,100000),522))));

Then the result should be: 100000

I have written a function to solve this problem but I need less bytes and less memory of codes.

My Function is:

function MaxArray($arr){
$length = count($arr);
global $maxValue;
for($i=0;$i<$length;$i++){
        if(is_int($arr[$i])){

                if($maxValue < $arr[$i]){
                    $maxValue = $arr[$i];
                }

        }
        elseif(is_array($arr[$i])){     
                MaxArray($arr[$i]);
            }
        }
    return $maxValue;   
}
  • 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-06-10T14:12:45+00:00Added an answer on June 10, 2026 at 2:12 pm

    Taken from PHP manual but authored by me:

    /**
     * @param array $array
     *
     * @return int|null Returns the largest value of the array. Returns NULL if no 
     *     integers are found.
     */
    function array_max_recursive(array $array) {
        $max = NULL;
        $stack = array($array);
    
        do {
            $current = array_pop($stack );
            foreach ($current as $value) {
                if (is_array($value)) {
                    $stack[] = $value;
                } elseif (filter_var($value, FILTER_VALIDATE_INT) !== FALSE) {
                    // max(NULL, 0) returns NULL, so cast it
                    $max = (int) max($max, $value);
                }
            }
    
        } while (!empty($stack));
    
        return $max;
    }
    

    • This function is not actually recursive, but fulfills the requirement that it works on sub-arrays. I enjoy doing things without the runtime stack from time to time.
    • It returns something of type int, never a string representation of an int. The exception is when you provide an array that does not contain any integers. It will then return NULL.
    • It ignores non-array, non-int values.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a static char array member initialized in terms of
I am new to Knockout.js, I have created an observable array and initialized with
Which is the best practice in this situation? I would like an un-initialized array
I initialized an Array as Double[][] myarr = Enumerable.Repeat(new double[12], 13).ToArray(); Then in a
I want to define initialized C-array in Pyrex, e.g. equivalent of: unsigned char a[8]
I have a very big constant array that is initialized at compile time. typedef
Why does the array a not get initialized by global variable size ? #include<stdio.h>
How do you access an array or variable declared or initialized in a nested
Possible Duplicate: Learning C++: polymorphism and slicing Array of polymorphic base class objects initialized
How do I initialize an array to 0? I have tried this. my @arr

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.