Arrays with unique entries

From MapbenderWiki

Jump to: navigation, search

The goal is to delete multiple occurences of an item in an array.

Example:

[0] => 1
[1] => 2
[2] => 1
[3] => 3

shall be changed into

[0] => 1
[1] => 2
[2] => 3

Contents

PHP

array_unique

see php.net. This function preserves the keys, the above would be changed into

[0] => 1
[1] => 2
[3] => 3

which is disastrous if you use for and not foreach

array_keys, array_flip

the following does not preserve the keys

array_keys( array_flip( someArray ));

so the result would indeed be

[0] => 1
[1] => 2
[2] => 3

JavaScript

no solution yet.

Personal tools