enter image description here

Tell me, please, the logic of the implementation of this range in php? I will receive different sets of numbers on the page, for example [5, 40, 100, 500] or [1000, 2000, 5000, 6500]. How to make ranges with such sets of numbers like in the picture?

  • Do you have any ideas at all? - teran
  • It would be possible to give a picture in the question more, otherwise there is nothing to be seen on it. - Raz Galstyan

1 answer 1

That is, it will be necessary to form ranges. Can so

function diap($num, $diap = array()) { $aRes = array(); if (sizeof($diap) == 0) { return $aRes; } if (sizeof($diap) == 1) { return array('< '. $diap[0], '> '.$diap[0]); } for ($i = 0; $i < sizeof($diap); $i++) { if ($i == 0) { $aRes[] = '< '.$diap[$i]; } elseif ($i == sizeof($diap) - 1) { $aRes[] = '> '.$diap[$i]; } else { $aRes[] = $diap[$i] .' - ' . $diap[$i+1]; } } return $aRes; }