Copy codeThe Code is as follows:
<? Php
/**
* Triple Triplet
*
*/
Class Triplet
{
Private $ _ data = null;
// Initialize the productkey, devicename, and devicesecret
Public function init ($ val1, $ val2, $ val3)
{
$ This-> _ data [0] = $ val1;
$ This-> _ data [1] = $ val2;
$ This-> _ data [2] = $ val3;
Return true;
}
// Destroy the productkey, devicename, and devicesecret
Public function destroy ()
{
Unset ($ this-> _ data );
Return true;
}
// Returns the value of $ key.
Public function get ($ key)
{
If ($ key <1 | $ key> 3) return false;
Return $ this-> _ data [$ key-1];
}
// Set the value of $ key to $ val.
Public function put ($ key, $ val)
{
If ($ key <1 | $ key> 3) return false;
$ This-> _ data [$ key-1] = $ val;
Return true;
}
// Whether to sort data in ascending order
Public function isAscending ()
{
Return ($ this-> _ data [0] <= $ this-> _ data [1]) & ($ this-> _ data [1] <= $ this-> _ data [2]);
}
// Sort by descending order
Public function isDescending ()
{
Return ($ this-> _ data [0] >=$ this-> _ data [1]) & ($ this-> _ data [1] >=$ this-> _ data [2]);
}
// Obtain the maximum value
Public function max ()
{
Return ($ this-> _ data [0] >=$ this-> _ data [1])? ($ This-> _ data [0] >=$ this-> _ data [2])? $ This-> _ data [0]: $ this-> _ data [2]: ($ this-> _ data [1] >=$ this-> _ data [2])? $ This-> _ data [1]: $ this-> _ data [2];
}
// Obtain the minimum value
Public function min ()
{
Return ($ this-> _ data [0] <= $ this-> _ data [1])? ($ This-> _ data [0] <= $ this-> _ data [2])? $ This-> _ data [0]: $ this-> _ data [2]: ($ this-> _ data [1] <= $ this-> _ data [2])? $ This-> _ data [1]: $ this-> _ data [2];
}
}
//
$ ObjTriplet = new Triplet ();
Echo "init:"; var_dump ($ objTriplet-> init (1, 2, 3); echo "<br/> ";
Echo "get 1:"; var_dump ($ objTriplet-> get (1); echo "<br/> ";
Echo "get 4:"; var_dump ($ objTriplet-> get (4); echo "<br/>"; // false
Echo "put 3, 4:"; var_dump ($ objTriplet-> put (3, 4); echo "<br/> ";
Echo "max:"; var_dump ($ objTriplet-> max (); echo "<br/> ";
Echo "min:"; var_dump ($ objTriplet-> min (); echo "<br/> ";
Echo "isAscending:"; var_dump ($ objTriplet-> isAscending (); echo "<br/> ";
Echo "isDescending:"; var_dump ($ objTriplet-> isDescending (); echo "<br/> ";
?>