<?php namespace Training; interface ITestSortInterface { /** * * * array(2,5,3,5,6,7,8,9,25,24,18,26,27,28,29,30,31) * */ public function testSort1($array); /** * * * array( * '1'=>array('price'=>10,'count'=>2), * '2'=>array('price'=>5,'count'=>5), * '3'=>array('price'=>8,'count'=>5), * '4'=>array('price'=>12,'count'=>4), * '5'=>array('price'=>8,'count'=>4), * ) * * 'price' DESC 'count' DESC * array( * '2'=>array('price'=>5,'count'=>2), * '5'=>array('price'=>8,'count'=>4), * '3'=>array('price'=>8,'count'=>5), * '1'=>array('price'=>10,'count'=>5), * '4'=>array('price'=>12,'count'=>4), * ) * */ public function testSort2($array); /** * * * array( * array(10,5,3,6), * array(8,2,11,13), * array(9,25,30,18), * array(34,37,38,24) * ) * * * array( * array(2,5,3,6), * array(8,10,11,13), * array(9,25,24,18), * array(34,37,38,30) * ) * */ public function testSort3($array); }
<?php // require_once('loader.php'); use Training\ITestSortInterface; use Training\Data; // Test ITestSortInterface class Test implements ITestSortInterface { /** * * * array(2,5,3,5,6,7,8,9,25,24,18,26,27,28,29,30,31) * */ public function testSort1($array) { // if (!$lenght = count($array)) return $array; // $x = $y = array(); // , , . // - $i = 1 for ($i = 1; $i < $lenght; $i++) { if ($array[$i] > $array[0]) $x[] = $array[$i]; else $y[] = $array[$i]; } return array_merge($this->testSort1($y), array($array[0]), $this->testSort1($x)); } /** * * * array( * '1'=>array('price'=>10,'count'=>2), * '2'=>array('price'=>5,'count'=>5), * '3'=>array('price'=>8,'count'=>5), * '4'=>array('price'=>12,'count'=>4), * '5'=>array('price'=>8,'count'=>4), * ) * * 'price' DESC 'count' DESC * array( * '2'=>array('price'=>5,'count'=>2), * '5'=>array('price'=>8,'count'=>4), * '3'=>array('price'=>8,'count'=>5), * '1'=>array('price'=>10,'count'=>5), * '4'=>array('price'=>12,'count'=>4), * ) * */ public function testSort2($array) { // TODO: Implement testSort2() method. } /** * * * array( * array(10,5,3,6), * array(8,2,11,13), * array(9,25,30,18), * array(34,37,38,24) * ) * * * array( * array(2,5,3,6), * array(8,10,11,13), * array(9,25,24,18), * array(34,37,38,30) * ) * */ public function testSort3($array) { // TODO: Implement testSort3() method. } } $test = new Test(); /** * . * \FireDog\FB::info() - * Data::getData(Data::ARR_SIMPL_INT) - */ \FireDog\FB::info($test->testSort1(Data::getData(Data::ARR_SIMPL_INT)));
Source: https://habr.com/ru/post/266925/
All Articles