Skip to content

Instantly share code, notes, and snippets.

@lloc lloc/MslsGetSet.php
Last active Aug 29, 2015

Embed
What would you like to do?
$obj = new MslsGetSet;
$obj->tmp = 'test';
$val = $obj->get_arr(); // array( 'tmp' => 'test' ) == $val
$val = $obj->has_value( 'tmp' ); // true == $val
$val = $obj->is_empty(); // false == $val
echo $obj->tmp; // Output: test
$obj->reset();
$val = $obj->get_arr(); // array() == $val
$val = $obj->has_value( 'tmp' ); // false == $val
$val = $obj->is_empty(); // true == $val
echo $obj->tmp; // Output:
$obj = new MslsJson;
$obj->add( null, 'Test 3' )
->add( '2', 'Test 2' )
->add( 1, 'Test 1' );
// Output: [{"value":1,"label":"Test 1"},{"value":2,"label":"Test 2"},{"value":0,"label":"Test 3"}]
echo $obj;
$arr = array(
'it' => 1,
'de_DE' => 2,
);
$obj = new MslsLanguageArray( $arr );
$val = $obj->get_val( 'it' ); // 1 == $val
$val = $obj->get_val( 'fr_FR' ); // 0 == $val
$val = $obj->get_arr(); // array( 'it' => 1, 'de_DE' => 2 ) == $val
$val = $obj->get_arr( 'de_DE' ); // array( 'it' => 1 ) == $val
// __CLASS__ and __METHOD__ are just for creating a unique footprint here
$cache = MslsSqlCacher::init( __CLASS__ )->set_params( __METHOD__ );
// With MslsSqlCacher you can use everything from WPDB as usual
$var = $cache->get_results(
$cache->prepare(
"SELECT ID FROM {$cache->posts} WHERE YEAR(post_date) = %d AND post_status = 'publish'",
date( 'Y' )
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.