Javascript timed array iteration

Sometimes you need to iterate on an array with a time delay between each iteration. For example, you have a list of UI elements. And you want to perform animation or process each components in a way to make it visible to user. If you dont use any delay there will be no UI feedback. User will think everything happened at once. Its better to provide an UI feedback on the work in progress.

Timed array iteration means you use a delay on each iteration. JavaScript has no sleep method. So its not possible to add delay like other languages. I used `window.setTimeout ` to achieve this. This is only available on browser based JavaScript. In server side JavaScript like nodejs, v8, rhino its not available. Here is the function.

function arrayWalkTimed(arr, dur, func){
    var p = arr[0]? arr[0]: null;
            timed_array_walk(arr.slice(1), dur, func);
        }, dur);

Convert an PHP array to object

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(
"name"=> "john",
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.
echo "values are identical", PHP_EOL;
echo "values are not identical", PHP_EOL;