1--TEST-- 2Test fprintf() function (variation - 1) 3--FILE-- 4<?php 5 6$float_variation = array( "%f","%-f", "%+f", "%7.2f", "%-7.2f", "%07.2f", "%-07.2f", "%'#7.2f" ); 7$float_numbers = array( 0, 1, -1, 0.32, -0.32, 3.4. -3.4, 2.54, -2.54 ); 8 9/* creating dumping file */ 10$data_file = __DIR__ . '/fprintf_variation_001.txt'; 11if (!($fp = fopen($data_file, 'wt'))) 12 return; 13 14$counter = 1; 15/* float type variations */ 16fprintf($fp, "\n*** Testing fprintf() with floats ***\n"); 17 18foreach( $float_variation as $float_var ) { 19 fprintf( $fp, "\n-- Iteration %d --\n",$counter); 20 foreach( $float_numbers as $float_num ) { 21 fprintf( $fp, "\n"); 22 fprintf( $fp, $float_var, $float_num ); 23 } 24 $counter++; 25} 26 27fclose($fp); 28print_r(file_get_contents($data_file)); 29echo "\nDone"; 30 31unlink($data_file); 32 33?> 34--EXPECT-- 35*** Testing fprintf() with floats *** 36 37-- Iteration 1 -- 38 390.000000 401.000000 41-1.000000 420.320000 43-0.320000 443.400000 452.540000 46-2.540000 47-- Iteration 2 -- 48 490.000000 501.000000 51-1.000000 520.320000 53-0.320000 543.400000 552.540000 56-2.540000 57-- Iteration 3 -- 58 59+0.000000 60+1.000000 61-1.000000 62+0.320000 63-0.320000 64+3.400000 65+2.540000 66-2.540000 67-- Iteration 4 -- 68 69 0.00 70 1.00 71 -1.00 72 0.32 73 -0.32 74 3.40 75 2.54 76 -2.54 77-- Iteration 5 -- 78 790.00 801.00 81-1.00 820.32 83-0.32 843.40 852.54 86-2.54 87-- Iteration 6 -- 88 890000.00 900001.00 91-001.00 920000.32 93-000.32 940003.40 950002.54 96-002.54 97-- Iteration 7 -- 98 990.00000 1001.00000 101-1.0000 1020.32000 103-0.3200 1043.40000 1052.54000 106-2.5400 107-- Iteration 8 -- 108 109###0.00 110###1.00 111##-1.00 112###0.32 113##-0.32 114###3.40 115###2.54 116##-2.54 117Done 118