<?php
require_once('iviArray.class.php');
function mysort($a, $b)
{
if ($a == $b) return 0;
return ($a < $b) ? (1) : (-1);
}
function myfunc(&$val, $key, $search)
{
$val = str_replace($search, 'FOO BAR', strtolower($val));
}
$person = new iviArray(array(
'First' => 'Moritz',
'Last' => 'Geselle',
'Email' => 'SynDrome@web.de',
'Web' => 'www.freisein.tk'
));
$data = new iviArray(array(
'010',
'002',
'006',
'201',
'142',
'032'
));
print('<pre>');
print("Initial arrays:\n\n");
print("Person:\n");
$person->display();
print("\nData:\n");
$data->display();
print("\nCheck for equality:\n");
if ($person->equals($data)) {
print("true\n");
}
else {
print("false\n");
}
print("\n\nCreate ComboBoxes:\n");
print($person->createComboBox('person'));
print($data->createComboBox('data'));
// sort by values and preserve keys
$person->sort('values', array('keys' => true));
// natural sort by values in reverse order without preserving keys
$data->sort('natural', array('reverse' => true));
print("\n\nPerson (regular sort):\n");
$person->display();
print("\nData (natural sort):\n");
$data->display();
// sort by keys
$person->sort('keys');
print("\n\nPerson (sorted by keys):\n");
$person->display();
// sort by keys, using a user function called "mysort()" (mysort is equal to regular sort in reverse order)
$person->sort('user', array('user' => 'keys', 'function' => 'mysort'));
print("\nPerson (sorted by keys, using a user function called \"mysort()\"):\n");
$person->display();
// convert to string
$str = $person->toString();
print("\n\nPerson (converted to a string):\n$str\n");
// parse $str into $data
$data->parseString($str);
print("\nData (parsed from the person-string):\n");
$data->display();
$person->apply('walk', 'myfunc', 'm');
print("\n\nPerson (after applying callback function \"myfunc()\"):\n");
$person->display();
print('</pre>');
?>
|