Note that there are some explanatory texts on larger screens.

plurals
  1. POphp xml read out max value on each days
    text
    copied!<p>I have a problem where i tries to read out a max temperature value on each day from an xml file. My xml file looks like: </p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;temperature&gt; &lt;measure&gt; &lt;date&gt;2013-06-19 03:18&lt;/date&gt; &lt;sensor1&gt;25.38&lt;/sensor1&gt; &lt;/measure&gt; &lt;measure&gt; &lt;date&gt;2013-06-19 06:18&lt;/date&gt; &lt;sensor1&gt;26.38&lt;/sensor1&gt; &lt;/measure&gt; &lt;measure&gt; &lt;date&gt;2013-06-19 09:18&lt;/date&gt; &lt;sensor1&gt;30.31&lt;/sensor1&gt; &lt;/measure&gt; &lt;measure&gt; &lt;date&gt;2013-06-20 03:18&lt;/date&gt; &lt;sensor1&gt;25.31&lt;/sensor1&gt; &lt;/measure&gt; &lt;measure&gt; &lt;date&gt;2013-06-20 06:18&lt;/date&gt; &lt;sensor1&gt;23.34&lt;/sensor1&gt; &lt;/measure&gt; &lt;measure&gt; &lt;date&gt;2013-06-21 07:18&lt;/date&gt; &lt;sensor1&gt;26.31&lt;/sensor1&gt; &lt;/measure&gt; &lt;measure&gt; &lt;date&gt;2013-06-21 10:18&lt;/date&gt; &lt;sensor1&gt;25.31&lt;/sensor1&gt; &lt;/measure&gt; &lt;/temperature&gt; </code></pre> <p>And what i want as output is like:</p> <pre><code>06/19 max 30.31 06/20 max 25.31 06/21 max 26.31 </code></pre> <p>As im still learning php im stuck. The code i have produced so far is:</p> <pre><code>&lt;?php $xml = simplexml_load_file("test.xml"); $days = array(); $sens1Array = array(); foreach($xml as $temp){ $days[] = $temp-&gt;date . "," . $temp-&gt;sensor1; } $days = array_unique($days); foreach($days as $day){ $day= explode(",", $day); $time = date("m/d", strtotime($day[0])); echo $time . " "; echo "max " . $day[1]; echo "&lt;br&gt;"; } ?&gt; </code></pre> <p>Which outputs:</p> <pre><code>06/19 max 25.38 06/19 max 26.38 06/19 max 30.31 06/20 max 25.31 06/20 max 23.34 06/21 max 26.31 06/21 max 25.31 </code></pre> <p>So what im looking for is some code that can compare each day and only output the max value for that day. I have searched and tried a lot but i can't solve it. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload