1--TEST-- 2Test sprintf() function : usage variations - hexa formats with array values 3--FILE-- 4<?php 5/* Prototype : string sprintf(string $format [, mixed $arg1 [, mixed ...]]) 6 * Description: Return a formatted string 7 * Source code: ext/standard/formatted_print.c 8*/ 9 10echo "*** Testing sprintf() : hexa formats with array values ***\n"; 11 12// array of array values 13$array_values = array( 14 array(), 15 array(0), 16 array(1), 17 array(NULL), 18 array(null), 19 array("string"), 20 array(true), 21 array(TRUE), 22 array(false), 23 array(FALSE), 24 array(1,2,3,4), 25 array(1 => "One", "two" => 2) 26); 27 28// array of hexa formats 29$hexa_formats = array( 30 "%x", "%xx", "%lx", 31 "%Lx", " %x", "%x ", 32 "\t%x", "\n%x", "%4x", 33 "%30x", "%[0-9A-Fa-f]", "%*x" 34); 35 36$count = 1; 37foreach($array_values as $array_value) { 38 echo "\n-- Iteration $count --\n"; 39 40 foreach($hexa_formats as $format) { 41 var_dump( sprintf($format, $array_value) ); 42 } 43 $count++; 44}; 45 46echo "Done"; 47?> 48--EXPECTF-- 49*** Testing sprintf() : hexa formats with array values *** 50 51-- Iteration 1 -- 52string(1) "0" 53string(2) "0x" 54string(1) "0" 55string(1) "x" 56string(2) " 0" 57string(2) "0 " 58string(2) " 0" 59string(2) " 600" 61string(4) " 0" 62string(30) " 0" 63string(10) "0-9A-Fa-f]" 64string(1) "x" 65 66-- Iteration 2 -- 67string(1) "1" 68string(2) "1x" 69string(1) "1" 70string(1) "x" 71string(2) " 1" 72string(2) "1 " 73string(2) " 1" 74string(2) " 751" 76string(4) " 1" 77string(30) " 1" 78string(10) "0-9A-Fa-f]" 79string(1) "x" 80 81-- Iteration 3 -- 82string(1) "1" 83string(2) "1x" 84string(1) "1" 85string(1) "x" 86string(2) " 1" 87string(2) "1 " 88string(2) " 1" 89string(2) " 901" 91string(4) " 1" 92string(30) " 1" 93string(10) "0-9A-Fa-f]" 94string(1) "x" 95 96-- Iteration 4 -- 97string(1) "1" 98string(2) "1x" 99string(1) "1" 100string(1) "x" 101string(2) " 1" 102string(2) "1 " 103string(2) " 1" 104string(2) " 1051" 106string(4) " 1" 107string(30) " 1" 108string(10) "0-9A-Fa-f]" 109string(1) "x" 110 111-- Iteration 5 -- 112string(1) "1" 113string(2) "1x" 114string(1) "1" 115string(1) "x" 116string(2) " 1" 117string(2) "1 " 118string(2) " 1" 119string(2) " 1201" 121string(4) " 1" 122string(30) " 1" 123string(10) "0-9A-Fa-f]" 124string(1) "x" 125 126-- Iteration 6 -- 127string(1) "1" 128string(2) "1x" 129string(1) "1" 130string(1) "x" 131string(2) " 1" 132string(2) "1 " 133string(2) " 1" 134string(2) " 1351" 136string(4) " 1" 137string(30) " 1" 138string(10) "0-9A-Fa-f]" 139string(1) "x" 140 141-- Iteration 7 -- 142string(1) "1" 143string(2) "1x" 144string(1) "1" 145string(1) "x" 146string(2) " 1" 147string(2) "1 " 148string(2) " 1" 149string(2) " 1501" 151string(4) " 1" 152string(30) " 1" 153string(10) "0-9A-Fa-f]" 154string(1) "x" 155 156-- Iteration 8 -- 157string(1) "1" 158string(2) "1x" 159string(1) "1" 160string(1) "x" 161string(2) " 1" 162string(2) "1 " 163string(2) " 1" 164string(2) " 1651" 166string(4) " 1" 167string(30) " 1" 168string(10) "0-9A-Fa-f]" 169string(1) "x" 170 171-- Iteration 9 -- 172string(1) "1" 173string(2) "1x" 174string(1) "1" 175string(1) "x" 176string(2) " 1" 177string(2) "1 " 178string(2) " 1" 179string(2) " 1801" 181string(4) " 1" 182string(30) " 1" 183string(10) "0-9A-Fa-f]" 184string(1) "x" 185 186-- Iteration 10 -- 187string(1) "1" 188string(2) "1x" 189string(1) "1" 190string(1) "x" 191string(2) " 1" 192string(2) "1 " 193string(2) " 1" 194string(2) " 1951" 196string(4) " 1" 197string(30) " 1" 198string(10) "0-9A-Fa-f]" 199string(1) "x" 200 201-- Iteration 11 -- 202string(1) "1" 203string(2) "1x" 204string(1) "1" 205string(1) "x" 206string(2) " 1" 207string(2) "1 " 208string(2) " 1" 209string(2) " 2101" 211string(4) " 1" 212string(30) " 1" 213string(10) "0-9A-Fa-f]" 214string(1) "x" 215 216-- Iteration 12 -- 217string(1) "1" 218string(2) "1x" 219string(1) "1" 220string(1) "x" 221string(2) " 1" 222string(2) "1 " 223string(2) " 1" 224string(2) " 2251" 226string(4) " 1" 227string(30) " 1" 228string(10) "0-9A-Fa-f]" 229string(1) "x" 230Done 231