Remove duplicate values from an array in PHP

Today’s chalenge: How to remove the duplicate values from a PHP array?

after short search i found solution array_unique.

How this function works:


$input = array(1, 2, 2, 3, 3, 4);

$result = array_unique($input);

var_dump($result); ?>

will output:
array(4) {
[0]=> int(1)
[1]=> int(2)
[3]=> int(3)
[5]=> int(4)

Remember: Output of array_unique() will have the same key of input array.

Google Currents app updated !

US people have been able to use the Google Currents app to read various websites with magazine-style layout.

Now other countries can finally get in on the act as well. Google has release version 1.1 of the app for Android and iOS.

New version makes the service available worldwide with support for 44 languages, adds a number of other improvements:

  • the ability to select which editions have images for offline reading
  • instant online sync
  • translation for 38 languages
  • promised 7X performance boost

And the best – app is completely free, and adapts the layout to suit both phones and tablets.

Scan QR code below to download it for the platform of your choice.

XML to PHP array

Some times when working in PHP you need a way to convert an XML document into a serializable array. If you ever tried to serialize() and then unserialize() a SimpleXML or DOMDocument object, you know what I’m talking about.

Assume the following XML snippet:

<show name="The Simpsons">


I found quick but little dirty way to do convert such axml document to an array, using type casting and JSON functions. After this i can ensure there are no exotic values that would cause problems when unserializing:

$a = json_decode(json_encode((array) simplexml_load_string($tv)),1);

After this we get:

    [show] => Array
            [@attributes] => Array
                    [name] => The Simpsons)
            [husband] => Homer
            [wife] => Marge
            [kid] => Array
                    [0] => Bart
                    [1] => Lisa
                    [2] => Maggie