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?
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
|
show 4 more comments
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
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 doingmax($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
|
show 4 more comments
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
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
php
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 doingmax($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
|
show 4 more comments
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 doingmax($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
|
show 4 more comments
2 Answers
2
active
oldest
votes
put the array directly into the max function to get maximum value
max($this->items);
add a comment |
It turns out that the following works:
foreach($this->items as $item)
$something[] = $this->dels[$item] ;
$this->something = max($something);
Thanks for looking
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
put the array directly into the max function to get maximum value
max($this->items);
add a comment |
put the array directly into the max function to get maximum value
max($this->items);
add a comment |
put the array directly into the max function to get maximum value
max($this->items);
put the array directly into the max function to get maximum value
max($this->items);
answered Mar 21 at 14:16
guruprasad ksguruprasad ks
583
583
add a comment |
add a comment |
It turns out that the following works:
foreach($this->items as $item)
$something[] = $this->dels[$item] ;
$this->something = max($something);
Thanks for looking
add a comment |
It turns out that the following works:
foreach($this->items as $item)
$something[] = $this->dels[$item] ;
$this->something = max($something);
Thanks for looking
add a comment |
It turns out that the following works:
foreach($this->items as $item)
$something[] = $this->dels[$item] ;
$this->something = max($something);
Thanks for looking
It turns out that the following works:
foreach($this->items as $item)
$something[] = $this->dels[$item] ;
$this->something = max($something);
Thanks for looking
answered Mar 21 at 14:38
RiaRia
285319
285319
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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