min and max in multidimensional-array

后端 未结 7 477
深忆病人
深忆病人 2020-12-02 00:44

hi i am trying to find min and max values of x and y how can i find this min and max functions is not working correctly

$dataPoints = array(
 array(\'x\' =&g         


        
7条回答
  •  Happy的楠姐
    2020-12-02 01:13

    Try something like this:

    foreach($dataPoints as $point) {
        if (!isset($x) || $point['x'] > $x) {
            $x = $point['x'];
        }
        if (!isset($y) || $point['y'] > $y) {
            $y = $point['y'];
        }
    }
    

提交回复
热议问题