mirror of
https://github.com/php/php-src.git
synced 2025-01-08 20:17:28 +08:00
230 lines
3.4 KiB
PHP
230 lines
3.4 KiB
PHP
--TEST--
|
||
Test sprintf() function : usage variations - char formats with array values
|
||
--FILE--
|
||
<?php
|
||
/* Prototype : string sprintf(string $format [, mixed $arg1 [, mixed ...]])
|
||
* Description: Return a formatted string
|
||
* Source code: ext/standard/formatted_print.c
|
||
*/
|
||
|
||
echo "*** Testing sprintf() : char formats with array values ***\n";
|
||
|
||
// array of array values
|
||
$array_values = array(
|
||
array(),
|
||
array(0),
|
||
array(1),
|
||
array(NULL),
|
||
array(null),
|
||
array("string"),
|
||
array(true),
|
||
array(TRUE),
|
||
array(false),
|
||
array(FALSE),
|
||
array(1,2,3,4),
|
||
array(1 => "One", "two" => 2)
|
||
);
|
||
|
||
// array of char formats
|
||
$char_formats = array(
|
||
"%c", "%hc", "%lc",
|
||
"%Lc", " %c", "%c ",
|
||
"\t%c", "\n%c", "%4c",
|
||
"%30c", "%[a-bA-B@#$&]", "%*c"
|
||
);
|
||
|
||
$count = 1;
|
||
foreach($array_values as $array_value) {
|
||
echo "\n-- Iteration $count --\n";
|
||
|
||
foreach($char_formats as $format) {
|
||
var_dump( sprintf($format, $array_value) );
|
||
}
|
||
$count++;
|
||
};
|
||
|
||
echo "Done";
|
||
?>
|
||
--EXPECTF--
|
||
*** Testing sprintf() : char formats with array values ***
|
||
|
||
-- Iteration 1 --
|
||
string(1) " |