PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 3ms RepoModel.GetById 37ms app.codeStats 1ms

/hphp/test/zend/bad/ext/standard/tests/array/array_unique_variation3.php

http://github.com/facebook/hiphop-php
PHP | 64 lines | 33 code | 13 blank | 18 comment | 0 complexity | 63bc154fa279e0be74d29221fe46a636 MD5 | raw file
 1<?php
 2/* Prototype  : array array_unique(array $input)
 3 * Description: Removes duplicate values from array 
 4 * Source code: ext/standard/array.c
 5*/
 6
 7/*
 8 * Testing the functionality of array_unique() by passing different
 9 * associative arrays having different keys to $input argument.
10*/
11
12echo "*** Testing array_unique() : assoc. array with diff. keys passed to \$input argument ***\n";
13
14// get an unset variable
15$unset_var = 10;
16unset ($unset_var);
17
18// get a resource variable
19$fp = fopen(__FILE__, "r");
20
21// get a class
22class classA
23{
24  public function __toString(){
25    return "Class A object";
26  }
27}
28
29// get a heredoc string
30$heredoc = <<<EOT
31Hello world
32EOT;
33
34// different associative arrays to be passed to $input argument
35$inputs = array (
36/*1*/  // arrays with integer keys
37       array(0 => "0", 1 => "0"),
38       array(1 => "1", 2 => "2", 3 => 1, 4 => "4"),
39
40       // arrays with float keys
41/*3*/  array(2.3333 => "float", 44.44 => "float"),
42       array(1.2 => "f1", 3.33 => "f2", 4.89999922839999 => "f1", 3333333.333333 => "f4"),
43
44       // arrays with string keys
45/*5*/  array('\tHello' => 111, 're\td' => "color", '\v\fworld' => 2.2, 'pen\n' => 111),
46       array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 111),
47       array("hello", $heredoc => "string", "string"),
48
49       // array with object, unset variable and resource variable
50/*8*/ array(new classA() => 11, @$unset_var => "hello", $fp => 'resource', 11, "hello"),
51);
52
53// loop through each sub-array of $inputs to check the behavior of array_unique()
54$iterator = 1;
55foreach($inputs as $input) {
56  echo "-- Iteration $iterator --\n";
57  var_dump( array_unique($input) );
58  $iterator++;
59}
60
61fclose($fp);
62  
63echo "Done";
64?>