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

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현