1--TEST-- 2Test compact() function : basic functionality 3--FILE-- 4<?php 5/* Prototype : proto array compact(mixed var_names [, mixed ...]) 6 * Description: Creates a hash containing variables and their values 7 * Source code: ext/standard/array.c 8 * Alias to functions: 9 */ 10 11/* 12 * Test basic functionality 13 */ 14 15echo "*** Testing compact() : basic functionality ***\n"; 16 17$a=1; 18$b=0.2; 19$c=true; 20$d=array("key"=>"val"); 21$e=NULL; 22$f="string"; 23 24// simple array test 25var_dump (compact(array("a", "b", "c", "d", "e", "f"))); 26// simple parameter test 27var_dump (compact("a", "b", "c", "d", "e", "f")); 28var_dump (compact(array("keyval"=>"a", "b"=>"b", "c"=>1))); 29 30// cases which should not yield any output. 31var_dump (compact(array(10, 0.3, true, array(20), NULL))); 32var_dump (compact(10, 0.3, true, array(20), NULL)); 33var_dump (compact(array("g"))); 34 35echo "Done"; 36?> 37--EXPECTF-- 38*** Testing compact() : basic functionality *** 39array(6) { 40 ["a"]=> 41 int(1) 42 ["b"]=> 43 float(0.2) 44 ["c"]=> 45 bool(true) 46 ["d"]=> 47 array(1) { 48 ["key"]=> 49 string(3) "val" 50 } 51 ["e"]=> 52 NULL 53 ["f"]=> 54 string(6) "string" 55} 56array(6) { 57 ["a"]=> 58 int(1) 59 ["b"]=> 60 float(0.2) 61 ["c"]=> 62 bool(true) 63 ["d"]=> 64 array(1) { 65 ["key"]=> 66 string(3) "val" 67 } 68 ["e"]=> 69 NULL 70 ["f"]=> 71 string(6) "string" 72} 73array(2) { 74 ["a"]=> 75 int(1) 76 ["b"]=> 77 float(0.2) 78} 79array(0) { 80} 81array(0) { 82} 83 84Notice: compact(): Undefined variable: g in %s on line %d 85array(0) { 86} 87Done 88