How to get/use the maximum value of an arrayPHP and EnumerationsPHP: Delete an element from an arrayConvert HTML + CSS to PDF with PHP?Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (CodeIgniter + XML-RPC)Can I bind an array to an IN() condition?How do I get a YouTube video thumbnail from the YouTube API?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?What are Long-Polling, Websockets, Server-Sent Events (SSE) and Comet?Reference - What does this error mean in PHP?

node command while defining a coordinate in TikZ

Invariance of results when scaling explanatory variables in logistic regression, is there a proof?

Is there a problem with hiding "forgot password" until it's needed?

Is it okay / does it make sense for another player to join a running game of Munchkin?

For airliners, what prevents wing strikes on landing in bad weather?

Can I create an upright 7-foot × 5-foot wall with the Minor Illusion spell?

How to interpret the phrase "t’en a fait voir à toi"?

How do ultrasonic sensors differentiate between transmitted and received signals?

A social experiment. What is the worst that can happen?

Can a controlled ghast be a leader of a pack of ghouls?

Is there enough fresh water in the world to eradicate the drinking water crisis?

Is there an wasy way to program in Tikz something like the one in the image?

Can a Bard use an arcane focus?

Can a Gentile theist be saved?

Teaching indefinite integrals that require special-casing

Simple image editor tool to draw a simple box/rectangle in an existing image

Are Warlocks Arcane or Divine?

Resetting two CD4017 counters simultaneously, only one resets

What is Sitecore Managed Cloud?

Identify a stage play about a VR experience in which participants are encouraged to simulate performing horrific activities

The One-Electron Universe postulate is true - what simple change can I make to change the whole universe?

Calculating the number of days between 2 dates in Excel

Reply ‘no position’ while the job posting is still there (‘HiWi’ position in Germany)

Simulating a probability of 1 of 2^N with less than N random bits



How to get/use the maximum value of an array


PHP and EnumerationsPHP: Delete an element from an arrayConvert HTML + CSS to PDF with PHP?Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (CodeIgniter + XML-RPC)Can I bind an array to an IN() condition?How do I get a YouTube video thumbnail from the YouTube API?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?What are Long-Polling, Websockets, Server-Sent Events (SSE) and Comet?Reference - What does this error mean in PHP?













-1















I have and array of numbers which I can retrieve as follows:



foreach ($this->items as $item) 
$this->something += ($this->dels[$item]) ;



what this does is adds all the $this->dels[$item] values up, however I would like to get the highest value from this and then use it. I have tried the following:



foreach ($this->items as $item) 
$this->something = max($this->dels[$item]);



however this returns $this->something = 0
any help welcome










share|improve this question
























  • max comparing 2 values and returns the highest one

    – myxaxa
    Mar 21 at 13:43






  • 1





    the highest value from this What is this?

    – AbraCadaver
    Mar 21 at 13:44







  • 6





    If you want the maximum of the array - no need for a loop just $this->something = max($this->dels) ;

    – Nigel Ren
    Mar 21 at 13:45











  • @Ria Why are you doing max($this->dels[$item]) ? Does $this->dels[$item] itself contain an array?

    – programmer-man
    Mar 21 at 13:46







  • 1





    “however I would like to get the highest value from this and then use it” - use it for what? Your description of what you are actually trying to achieve here is more than unclear. Using max inside that loop probably makes no sense whatsoever though.

    – 04FS
    Mar 21 at 14:08















-1















I have and array of numbers which I can retrieve as follows:



foreach ($this->items as $item) 
$this->something += ($this->dels[$item]) ;



what this does is adds all the $this->dels[$item] values up, however I would like to get the highest value from this and then use it. I have tried the following:



foreach ($this->items as $item) 
$this->something = max($this->dels[$item]);



however this returns $this->something = 0
any help welcome










share|improve this question
























  • max comparing 2 values and returns the highest one

    – myxaxa
    Mar 21 at 13:43






  • 1





    the highest value from this What is this?

    – AbraCadaver
    Mar 21 at 13:44







  • 6





    If you want the maximum of the array - no need for a loop just $this->something = max($this->dels) ;

    – Nigel Ren
    Mar 21 at 13:45











  • @Ria Why are you doing max($this->dels[$item]) ? Does $this->dels[$item] itself contain an array?

    – programmer-man
    Mar 21 at 13:46







  • 1





    “however I would like to get the highest value from this and then use it” - use it for what? Your description of what you are actually trying to achieve here is more than unclear. Using max inside that loop probably makes no sense whatsoever though.

    – 04FS
    Mar 21 at 14:08













-1












-1








-1








I have and array of numbers which I can retrieve as follows:



foreach ($this->items as $item) 
$this->something += ($this->dels[$item]) ;



what this does is adds all the $this->dels[$item] values up, however I would like to get the highest value from this and then use it. I have tried the following:



foreach ($this->items as $item) 
$this->something = max($this->dels[$item]);



however this returns $this->something = 0
any help welcome










share|improve this question
















I have and array of numbers which I can retrieve as follows:



foreach ($this->items as $item) 
$this->something += ($this->dels[$item]) ;



what this does is adds all the $this->dels[$item] values up, however I would like to get the highest value from this and then use it. I have tried the following:



foreach ($this->items as $item) 
$this->something = max($this->dels[$item]);



however this returns $this->something = 0
any help welcome







php






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 21 at 13:45









Magnus Eriksson

7,58341328




7,58341328










asked Mar 21 at 13:42









RiaRia

285319




285319












  • max comparing 2 values and returns the highest one

    – myxaxa
    Mar 21 at 13:43






  • 1





    the highest value from this What is this?

    – AbraCadaver
    Mar 21 at 13:44







  • 6





    If you want the maximum of the array - no need for a loop just $this->something = max($this->dels) ;

    – Nigel Ren
    Mar 21 at 13:45











  • @Ria Why are you doing max($this->dels[$item]) ? Does $this->dels[$item] itself contain an array?

    – programmer-man
    Mar 21 at 13:46







  • 1





    “however I would like to get the highest value from this and then use it” - use it for what? Your description of what you are actually trying to achieve here is more than unclear. Using max inside that loop probably makes no sense whatsoever though.

    – 04FS
    Mar 21 at 14:08

















  • max comparing 2 values and returns the highest one

    – myxaxa
    Mar 21 at 13:43






  • 1





    the highest value from this What is this?

    – AbraCadaver
    Mar 21 at 13:44







  • 6





    If you want the maximum of the array - no need for a loop just $this->something = max($this->dels) ;

    – Nigel Ren
    Mar 21 at 13:45











  • @Ria Why are you doing max($this->dels[$item]) ? Does $this->dels[$item] itself contain an array?

    – programmer-man
    Mar 21 at 13:46







  • 1





    “however I would like to get the highest value from this and then use it” - use it for what? Your description of what you are actually trying to achieve here is more than unclear. Using max inside that loop probably makes no sense whatsoever though.

    – 04FS
    Mar 21 at 14:08
















max comparing 2 values and returns the highest one

– myxaxa
Mar 21 at 13:43





max comparing 2 values and returns the highest one

– myxaxa
Mar 21 at 13:43




1




1





the highest value from this What is this?

– AbraCadaver
Mar 21 at 13:44






the highest value from this What is this?

– AbraCadaver
Mar 21 at 13:44





6




6





If you want the maximum of the array - no need for a loop just $this->something = max($this->dels) ;

– Nigel Ren
Mar 21 at 13:45





If you want the maximum of the array - no need for a loop just $this->something = max($this->dels) ;

– Nigel Ren
Mar 21 at 13:45













@Ria Why are you doing max($this->dels[$item]) ? Does $this->dels[$item] itself contain an array?

– programmer-man
Mar 21 at 13:46






@Ria Why are you doing max($this->dels[$item]) ? Does $this->dels[$item] itself contain an array?

– programmer-man
Mar 21 at 13:46





1




1





“however I would like to get the highest value from this and then use it” - use it for what? Your description of what you are actually trying to achieve here is more than unclear. Using max inside that loop probably makes no sense whatsoever though.

– 04FS
Mar 21 at 14:08





“however I would like to get the highest value from this and then use it” - use it for what? Your description of what you are actually trying to achieve here is more than unclear. Using max inside that loop probably makes no sense whatsoever though.

– 04FS
Mar 21 at 14:08












2 Answers
2






active

oldest

votes


















0














put the array directly into the max function to get maximum value



max($this->items);





share|improve this answer






























    0














    It turns out that the following works:



    foreach($this->items as $item) 
    $something[] = $this->dels[$item] ;


    $this->something = max($something);


    Thanks for looking






    share|improve this answer






















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281816%2fhow-to-get-use-the-maximum-value-of-an-array%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      put the array directly into the max function to get maximum value



      max($this->items);





      share|improve this answer



























        0














        put the array directly into the max function to get maximum value



        max($this->items);





        share|improve this answer

























          0












          0








          0







          put the array directly into the max function to get maximum value



          max($this->items);





          share|improve this answer













          put the array directly into the max function to get maximum value



          max($this->items);






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 21 at 14:16









          guruprasad ksguruprasad ks

          583




          583























              0














              It turns out that the following works:



              foreach($this->items as $item) 
              $something[] = $this->dels[$item] ;


              $this->something = max($something);


              Thanks for looking






              share|improve this answer



























                0














                It turns out that the following works:



                foreach($this->items as $item) 
                $something[] = $this->dels[$item] ;


                $this->something = max($something);


                Thanks for looking






                share|improve this answer

























                  0












                  0








                  0







                  It turns out that the following works:



                  foreach($this->items as $item) 
                  $something[] = $this->dels[$item] ;


                  $this->something = max($something);


                  Thanks for looking






                  share|improve this answer













                  It turns out that the following works:



                  foreach($this->items as $item) 
                  $something[] = $this->dels[$item] ;


                  $this->something = max($something);


                  Thanks for looking







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 21 at 14:38









                  RiaRia

                  285319




                  285319



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281816%2fhow-to-get-use-the-maximum-value-of-an-array%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                      Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript