PHP Classes

File: examples/SortingandMultiSortingFunctions.php

Recommend this page to a friend!
  Classes of zinsou A.A.E.Moïse   PHP Dictionary to Array class   examples/SortingandMultiSortingFunctions.php   Download  
File: examples/SortingandMultiSortingFunctions.php
Role: Example script
Content type: text/plain
Description: example script
Class: PHP Dictionary to Array class
Manipulate value collections as arrays or objects
Author: By
Last change:
Date: 6 years ago
Size: 5,515 bytes
 

Contents

Class file image Download
with an xDict object no matter the data your xDict object contains you can use SORTING functions<br>
normally no matter the flags without stress of invalid data types errors.Of course for the methods<br>
which allow user defined callback you can use any type of callback(closure,normal function,classes non <br>static methods
or static methods as stated in the PHP doc.<br>
for the highlighted following sources you got the result below each source:<br>
<?php
require_once('./../xdict.class.php');
echo
'<pre>';
highlight_string('<?php
$ar=xdict(0,\'k\');
$ar->fill_with( array(
       array("10", 11, 100, 100, new xdict()),
       array( 1, 2, "2", 3, 1)
      )
      );
$ar->multisort($ar[\'k0\'], SORT_ASC, SORT_STRING,$ar[\'k1\'], SORT_NUMERIC, SORT_DESC);


var_dump($ar);

$data=xdict(0,\'k\');


$data[] = array(\'volume\' => 67, \'edition\' => 2);
$data[] = array(\'volume\' => 86, \'edition\' => 1);
$data[] = array(\'volume\' => 85, \'edition\' => 6);
$data[] = array(\'volume\' => 98, \'edition\' => 2);
$data[] = array(\'volume\' => 86, \'edition\' => 6);
$data[] = array(\'volume\' => 67, \'edition\' => 7);

foreach ($data as $key => $row) {
    $volume[$key] = $row[\'volume\'];
    $edition[$key] = $row[\'edition\'];
}
$v=xdict(0);$v->fill_with($volume);

$data->multisort($edition, SORT_ASC,$volume, SORT_DESC );

$array=xdict(0,\'k\');
$array->fill_with(array(\'Alpha\', \'atomic\', \'Beta\', \'bank\',7,$x=xdict()));
$array_lowercase =$array->map(\'strtolower\');

$array->multisort($array_lowercase, SORT_ASC, SORT_STRING);
var_dump($array);
?>'
);

$ar=xdict(0,'k');
$ar->fill_with( array(
       array(
"10", 11, 100, 100, new xdict()),
       array(
1, 2, "2", 3, 1)
      )
      );
$ar->multisort($ar['k0'], SORT_ASC, SORT_STRING,$ar['k1'], SORT_NUMERIC, SORT_DESC);


var_dump($ar);

$data=xdict(0,'k');


$data[] = array('volume' => 67, 'edition' => 2);
$data[] = array('volume' => 86, 'edition' => 1);
$data[] = array('volume' => 85, 'edition' => 6);
$data[] = array('volume' => 98, 'edition' => 2);
$data[] = array('volume' => 86, 'edition' => 6);
$data[] = array('volume' => 67, 'edition' => 7);

foreach (
$data as $key => $row) {
   
$volume[$key] = $row['volume'];
   
$edition[$key] = $row['edition'];
}
$v=xdict(0);$v->fill_with($volume);

$data->multisort($volume, SORT_DESC, $edition, SORT_ASC);
var_dump($data);
$array=xdict(0,'k');
$array->fill_with(array('Alpha', 'atomic', 'Beta', 'bank',7,$x=xdict()));
$array_lowercase =$array->map('strtolower');

$array->multisort($array_lowercase, SORT_ASC, SORT_STRING);
var_dump($array);
highlight_string('<?php
$array=xdict(0,\'k\');
$array->fill_with(array(\'alpha\', \'atomic\', \'beta\', \'bank\'));
$array->sort(SORT_STRING);
var_dump($array);
$array->rsort(SORT_STRING);
var_dump($array);
$array->asort(SORT_STRING);
var_dump($array);
$array->arsort(SORT_STRING);
var_dump($array);
?'
);
$array=xdict(0,'k');
$array->fill_with(array('alpha', 'atomic', 'beta', 'bank'));
$array->sort(SORT_STRING);
var_dump($array);
$array->rsort(SORT_STRING);
var_dump($array);
$array->asort(SORT_STRING);
var_dump($array);
$array->arsort(SORT_STRING);
var_dump($array);
highlight_string('<?php
$array=xdict(0,\'k\');
$array->fill_with(array(\'Alpha\', \'atomic\', \'Beta\', \'bank\'));
$array->ksort();
var_dump($array);
$array->krsort();
var_dump($array);
$array->natsort();
var_dump($array);
$array->natcasesort();
var_dump($array);
?'
);
$array=xdict(0,'k');
$array->fill_with(array('Alpha', 'atomic', 'Beta', 'bank'));
$array->ksort();
var_dump($array);
$array->krsort();
var_dump($array);
$array->natsort();
var_dump($array);
$array->natcasesort();
var_dump($array);


highlight_string('<?php

function cmp($a, $b) {
    if ($a == $b) {
        return 0;
    }
    return ($a < $b) ? -1 : 1;
}


$array = array(\'a\' => 4, \'b\' => 8, \'c\' => -1, \'d\' => -9, \'e\' => 2, \'f\' => 5, \'g\' => 3, \'h\' => -4);
$obj=xdict(0,\'\',false);
$obj($array);

$obj->uasort(\'cmp\');
var_dump($obj);
?>'
);

function
cmp($a, $b) {
    if (
$a == $b) {
        return
0;
    }
    return (
$a < $b) ? -1 : 1;
}


$array = array('a' => 4, 'b' => 8, 'c' => -1, 'd' => -9, 'e' => 2, 'f' => 5, 'g' => 3, 'h' => -4);
$obj=xdict(0,'',false);
$obj($array);

$obj->uasort('cmp');
var_dump($obj);

highlight_string('<?php

function cmp($a, $b) {
    if ($a == $b) {
        return 0;
    }
    return ($a < $b) ? -1 : 1;
}


$array = array_flip(array(\'a\' => 4, \'b\' => 8, \'c\' => -1, \'d\' => -9, \'e\' => 2, \'f\' => 5, \'g\' => 3, \'h\' => -4));
$obj=xdict(0,\'\',false);
$obj($array);

$obj->uasort(\'cmp\');
var_dump($obj);
?>'
);




$array =array_flip(array('a' => 4, 'b' => 8, 'c' => -1, 'd' => -9, 'e' => 2, 'f' => 5, 'g' => 3, 'h' => -4));
$obj=xdict(0,'',false);
$obj($array);

$obj->uksort('cmp');
var_dump($obj);

highlight_string('<?php

function cmp($a, $b) {
    if ($a == $b) {
        return 0;
    }
    return ($a < $b) ? -1 : 1;
}


$array = array(\'a\' => 4, \'b\' => 8, \'c\' => -1, \'d\' => -9, \'e\' => 2, \'f\' => 5, \'g\' => 3, \'h\' => -4);
$obj=xdict(0,\'\',false);
$obj($array);

$obj->usort(\'cmp\');
var_dump($obj);
?>'
);




$array = array('a' => 4, 'b' => 8, 'c' => -1, 'd' => -9, 'e' => 2, 'f' => 5, 'g' => 3, 'h' => -4);
$obj=xdict(0,'',false);
$obj($array);

$obj->usort('cmp');
var_dump($obj);

?>