1--TEST-- 2Test sprintf() function : usage variations - scientific 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() : scientific 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(100000000000), 18 array(.0000001), 19 array(10e2), 20 array(NULL), 21 array(null), 22 array("string"), 23 array(true), 24 array(TRUE), 25 array(false), 26 array(FALSE), 27 array(1,2,3,4), 28 array(1 => "One", "two" => 2) 29); 30 31// array of scientific formats 32$scientific_formats = array( 33 "%e", "%he", "%le", 34 "%Le", " %e", "%e ", 35 "\t%e", "\n%e", "%4e", 36 "%30e", "%[0-1]", "%*e" 37); 38 39$count = 1; 40foreach($array_values as $array_value) { 41 echo "\n-- Iteration $count --\n"; 42 43 foreach($scientific_formats as $format) { 44 var_dump( sprintf($format, $array_value) ); 45 } 46 $count++; 47}; 48 49echo "Done"; 50?> 51--EXPECTF-- 52*** Testing sprintf() : scientific formats with array values *** 53 54-- Iteration 1 -- 55string(11) "0.000000e+0" 56string(1) "e" 57string(11) "0.000000e+0" 58string(1) "e" 59string(12) " 0.000000e+0" 60string(12) "0.000000e+0 " 61string(12) " 0.000000e+0" 62string(12) " 630.000000e+0" 64string(11) "0.000000e+0" 65string(30) " 0.000000e+0" 66string(4) "0-1]" 67string(1) "e" 68 69-- Iteration 2 -- 70string(11) "1.000000e+0" 71string(1) "e" 72string(11) "1.000000e+0" 73string(1) "e" 74string(12) " 1.000000e+0" 75string(12) "1.000000e+0 " 76string(12) " 1.000000e+0" 77string(12) " 781.000000e+0" 79string(11) "1.000000e+0" 80string(30) " 1.000000e+0" 81string(4) "0-1]" 82string(1) "e" 83 84-- Iteration 3 -- 85string(11) "1.000000e+0" 86string(1) "e" 87string(11) "1.000000e+0" 88string(1) "e" 89string(12) " 1.000000e+0" 90string(12) "1.000000e+0 " 91string(12) " 1.000000e+0" 92string(12) " 931.000000e+0" 94string(11) "1.000000e+0" 95string(30) " 1.000000e+0" 96string(4) "0-1]" 97string(1) "e" 98 99-- Iteration 4 -- 100string(11) "1.000000e+0" 101string(1) "e" 102string(11) "1.000000e+0" 103string(1) "e" 104string(12) " 1.000000e+0" 105string(12) "1.000000e+0 " 106string(12) " 1.000000e+0" 107string(12) " 1081.000000e+0" 109string(11) "1.000000e+0" 110string(30) " 1.000000e+0" 111string(4) "0-1]" 112string(1) "e" 113 114-- Iteration 5 -- 115string(11) "1.000000e+0" 116string(1) "e" 117string(11) "1.000000e+0" 118string(1) "e" 119string(12) " 1.000000e+0" 120string(12) "1.000000e+0 " 121string(12) " 1.000000e+0" 122string(12) " 1231.000000e+0" 124string(11) "1.000000e+0" 125string(30) " 1.000000e+0" 126string(4) "0-1]" 127string(1) "e" 128 129-- Iteration 6 -- 130string(11) "1.000000e+0" 131string(1) "e" 132string(11) "1.000000e+0" 133string(1) "e" 134string(12) " 1.000000e+0" 135string(12) "1.000000e+0 " 136string(12) " 1.000000e+0" 137string(12) " 1381.000000e+0" 139string(11) "1.000000e+0" 140string(30) " 1.000000e+0" 141string(4) "0-1]" 142string(1) "e" 143 144-- Iteration 7 -- 145string(11) "1.000000e+0" 146string(1) "e" 147string(11) "1.000000e+0" 148string(1) "e" 149string(12) " 1.000000e+0" 150string(12) "1.000000e+0 " 151string(12) " 1.000000e+0" 152string(12) " 1531.000000e+0" 154string(11) "1.000000e+0" 155string(30) " 1.000000e+0" 156string(4) "0-1]" 157string(1) "e" 158 159-- Iteration 8 -- 160string(11) "1.000000e+0" 161string(1) "e" 162string(11) "1.000000e+0" 163string(1) "e" 164string(12) " 1.000000e+0" 165string(12) "1.000000e+0 " 166string(12) " 1.000000e+0" 167string(12) " 1681.000000e+0" 169string(11) "1.000000e+0" 170string(30) " 1.000000e+0" 171string(4) "0-1]" 172string(1) "e" 173 174-- Iteration 9 -- 175string(11) "1.000000e+0" 176string(1) "e" 177string(11) "1.000000e+0" 178string(1) "e" 179string(12) " 1.000000e+0" 180string(12) "1.000000e+0 " 181string(12) " 1.000000e+0" 182string(12) " 1831.000000e+0" 184string(11) "1.000000e+0" 185string(30) " 1.000000e+0" 186string(4) "0-1]" 187string(1) "e" 188 189-- Iteration 10 -- 190string(11) "1.000000e+0" 191string(1) "e" 192string(11) "1.000000e+0" 193string(1) "e" 194string(12) " 1.000000e+0" 195string(12) "1.000000e+0 " 196string(12) " 1.000000e+0" 197string(12) " 1981.000000e+0" 199string(11) "1.000000e+0" 200string(30) " 1.000000e+0" 201string(4) "0-1]" 202string(1) "e" 203 204-- Iteration 11 -- 205string(11) "1.000000e+0" 206string(1) "e" 207string(11) "1.000000e+0" 208string(1) "e" 209string(12) " 1.000000e+0" 210string(12) "1.000000e+0 " 211string(12) " 1.000000e+0" 212string(12) " 2131.000000e+0" 214string(11) "1.000000e+0" 215string(30) " 1.000000e+0" 216string(4) "0-1]" 217string(1) "e" 218 219-- Iteration 12 -- 220string(11) "1.000000e+0" 221string(1) "e" 222string(11) "1.000000e+0" 223string(1) "e" 224string(12) " 1.000000e+0" 225string(12) "1.000000e+0 " 226string(12) " 1.000000e+0" 227string(12) " 2281.000000e+0" 229string(11) "1.000000e+0" 230string(30) " 1.000000e+0" 231string(4) "0-1]" 232string(1) "e" 233 234-- Iteration 13 -- 235string(11) "1.000000e+0" 236string(1) "e" 237string(11) "1.000000e+0" 238string(1) "e" 239string(12) " 1.000000e+0" 240string(12) "1.000000e+0 " 241string(12) " 1.000000e+0" 242string(12) " 2431.000000e+0" 244string(11) "1.000000e+0" 245string(30) " 1.000000e+0" 246string(4) "0-1]" 247string(1) "e" 248 249-- Iteration 14 -- 250string(11) "1.000000e+0" 251string(1) "e" 252string(11) "1.000000e+0" 253string(1) "e" 254string(12) " 1.000000e+0" 255string(12) "1.000000e+0 " 256string(12) " 1.000000e+0" 257string(12) " 2581.000000e+0" 259string(11) "1.000000e+0" 260string(30) " 1.000000e+0" 261string(4) "0-1]" 262string(1) "e" 263 264-- Iteration 15 -- 265string(11) "1.000000e+0" 266string(1) "e" 267string(11) "1.000000e+0" 268string(1) "e" 269string(12) " 1.000000e+0" 270string(12) "1.000000e+0 " 271string(12) " 1.000000e+0" 272string(12) " 2731.000000e+0" 274string(11) "1.000000e+0" 275string(30) " 1.000000e+0" 276string(4) "0-1]" 277string(1) "e" 278Done