PHP stdClass Object within array

I have no idea what the stdClass Object is. I googled it but couldn’t find anything really informative about the stdClass.A Few articles on stackoverflow explains the basic idea behind stdClass but that’s it. I haven’t searched the official documentation though.

Anyways, this article is not about stdClass Object. It is about retrieving values from array whose members are of type stdClass.

Here is a link to official php array documentation : http://php.net/manual/en/language.types.array.php

Now if you print_r the simple multidimensional array It would look something like this.

Example array :

print_r($array)  of the above will give the following result.

Now if you want to access the value from “array” you can do that fairly easily with following code.

That is simple enough.

But sometimes you may also encounter an array which would look like this.

Now if you look at the array elements in the first dimension,they are of type stdClass Object. You can not just retrieve the value like we did before in the example.

Syntax to retrieve the values from the array similar to shown above is $array[0]->KEY.

We can also loop over array objects like this

Complete Example :

Output :

 

JavaScript : Time delayed page redirect.

Recently in one of the project I am working on required me to do a “JavaScript” based url redirect. Originally I used a PHP header based 301 redirect

But this approach has one  limitation.The limitation is that you can not send any data before the header. My client used third-party JavaScript based tracking service and he also wanted to use this service on a redirect page. ( Client demands. You deliver ). The code given below demonstrates the delayed JavaScript redirect. i.e redirect to a page after a pre specified delay in milliseconds.

 

Websites to test your programming skills

What you do once you have learned the basics of a new programming language ? Obviously you would want to test your skills ( Self evaluation ). There are few ways to test your ability to program , You could try to solve the programs given in the reference book or come up with a little project of your own. Either way it will help you improve your skills.

But if you would like to know how good you are at programming ( irrespective of the programming language ) compared to other programmers then you should examine one of the following Programming contest sites.

1. HackerRank

HackerRank formerly “InterviewStreet” was the first of its kind. HackerRank offers programming challenges of Artificial Intelligence, Algorithms, Functional Programming, Code Golf – Solve coding problems using the least number of keystrokes and Machine Learning.

HackerRank supports BASH, C, C++, Java, C#, PHP, Ruby, Perl, Haskell, Clojure, Scala, Lua, Go, 
Javascript, Erland, D, OCaml, Pascal, Python 2, Python 3, Groovy, Objective C, F#, VB.NET, LOLCODE, Smalltalk, Tcl, COBOL, Whitespace, Brainfuck, Lisp.

Click Here to check out theirs upcoming contests.

2. CodeChef

CodeChef is a noncommercial organization operated by Directi, an Indian software company based in Mumbai, India. You can either practice, take part in contests or discuss about programming challenges.

They support ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.8.1, CPP11, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC.

Supported Programming languages differ from challenge to challenge.

3. TopCoder

There are three types challenges you can take on TopCoder.

* Graphics Design
* Software Development
* Data Science

You could also win cash prizes if you finish in the top three places. Most of the challenges they offer are real world problems provided by real companies / organizations. 

4. programmr

Another favourite of mine is programmr. One of the cool feature of theirs is “Challenge your friend” which lets you challenge one of your friends.

I am not going to write about every site on the list. I recommended that you should explore each website on your own.Here is the rest of the list containing Competitive Programming and Online Judges websites.