Archive for the ‘php’ Category

Convert an PHP array to object

Monday, January 4th, 2010

How do you convert an php array stdClass object?

Many times, we have to convert array to stdClass objects for easy access. Yeah, easy access. At least for me. Cause typing [""] instead of -> requires 2 extra key press. I dont like that.

So how do you do it?

Its really simple, just cast the array with (object). It’ll become an stdClass.
See the following code,

$ar = array(
"age"=>27,
"name"=> "john",
"female"=>0
);
print_r($ar); // will print "Array" as type

// making it an object

$ob = (object) $ar;
print_r($ob); // will print "stdClass Object" as type

// compare the values.
if($ar["name"]===$ob->name)
echo "values are identical", PHP_EOL;
else
echo "values are not identical", PHP_EOL;

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Ping.fm Post to StumbleUpon

Decoding Encoded PHP Codes (Getting Dynamic)

Friday, March 6th, 2009

I saw many people want to decode their files. So I made a decoder. Cheers!

All you have to paste your code here. Then press ‘Go’.

Remember, the format of the code must be like the following.

/**
* Here dots (...) means long base64 data
*/
$o="......................";
eval(base64_decode("..............."));
return;

————————-
Thu, 06 Aug 2009 00:23:20
A little update.  I just added another type of decoder. now “eval(gzinflate(base64_decode(” type data can be decoded too.

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Ping.fm Post to StumbleUpon