Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is a possible solution for your problem, though I would recommend a re-construction as Patashu &amp; Nikola R stated.</p> <pre><code>$untrimmed = [["June 4",30],["June 4",35],["June 5",46],["June 5",38.33],["June 5",12]]; $trimmed = stripDates($untrimmed); function stripDates($dates) { foreach( $dates as $key=&gt;$date ) { if ($key&gt;0) { if ($date[0] === $dates[$key-1][0]) { $dates[$key][0] = ""; } else if($dates[$key-1][0] === "") { for ($i = $key-1; $i &gt; -1; $i--) { if ($date[0] === $dates[$i][0]) $dates[$key][0] = ""; if ($dates[$key] != "") break; } } } } return $dates; } // Note: This would require dates to be added chronically //Output: ["June 4",30],["",35],["June 5",46],["",38.33],["",12] </code></pre> <p>I would recommend something like this:</p> <pre><code>$unconstructed = [["June 4",30],["June 4",35],["June 5",46],["June 5",38.33],["June 5",12]]; $constructed = constructAssoc($unconstructed); function constructAssoc($dates) { $constructed = array(); foreach( $dates as $index=&gt;$date ) { if (!array_key_exists($date[0], $constructed)) { $constructed[$date[0]] = array("index"=&gt;$index, "value"=&gt;$date[1]); } else { array_push($constructed[$date[0], ["index"=&gt;$index,"value"=&gt;$date[1]]); } } return $constructed; } //Output: ["June 4"=&gt; [["index"=&gt;0, "value"=&gt;30], ["index"=&gt;1, "value"=&gt;35]], "June 5"=&gt;[["index"=&gt;2, "value"=&gt;46], ["index"=&gt;3, "value"=&gt;38.33], ["index"=&gt;4, "value"=&gt;12]]] </code></pre> <p>Note: Added index in recommended solution if a more accurate re-construction is needed.</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