min and max in multidimensional-array

后端 未结 7 446
深忆病人
深忆病人 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条回答
  • 2020-12-02 01:20

    I'm a Fan of the Underscore Library

    http://brianhaveri.github.com/Underscore.php/#max

    Not native but will save you from having write the function your self, plus many other functions :)

    oh and it becomes a one-liner!

    Example:

    include_once 'underscore.php';
    
    $dataPoints = array(
        array('x' => 2343, 'y' => 4322),
        array('x' => 103, 'y' => 303 ),
        array('x' => 2345,'y' => 2321 ),
        array('x' => 310, 'y' => 2044 ),
        array('x' => 173, 'y' => 793 ),
        array('x' => 456, 'y' => 2675),
        array('x' => 24, 'y' => 819 )
    );
    
    
    __::max($dataPoints, function($item) { return $item['x']; });    // array('x' => 2345,'y' => 2321 )
    __::min($dataPoints, function($item) { return $item['y']; });    // array('x' => 103, 'y' => 303 ) 
    
    0 讨论(0)
提交回复
热议问题