Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- error_reporting(E_ALL);
- trait Sorting {
- abstract public function Comparable($x,$y);
- function isSorted($object): bool
- {
- $sortedL = false;
- for ($i = 0; $i < count($object)-1; $i++) {
- if ($object->Comparable($object[$i+1],$object[$i])){
- $sortedL= true;
- }
- else{
- $sortedL= false;
- }
- }
- return $sortedL;
- }
- }
- class Sortingclass{
- use Sorting;
- public function Comparable($x,$y)
- {
- if($x < $y){
- return -1;
- }
- else{
- return 1;
- }
- }
- }
- $class1 = new Sortingclass;
- $info = array(1,2,3,4,5);
- $sort = $class1->isSorted($info);
- echo $sort;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement