diff options
Diffstat (limited to 'ext/standard/tests')
-rw-r--r-- | ext/standard/tests/array/array_pad_error.phpt | 53 | ||||
-rw-r--r-- | ext/standard/tests/array/array_pad_variation1.phpt | 270 | ||||
-rw-r--r-- | ext/standard/tests/array/array_pad_variation2.phpt | 256 | ||||
-rw-r--r-- | ext/standard/tests/array/array_pad_variation3.phpt | 873 | ||||
-rw-r--r-- | ext/standard/tests/array/array_pad_variation4.phpt | 60 | ||||
-rw-r--r-- | ext/standard/tests/array/array_pad_variation5.phpt | 140 | ||||
-rw-r--r-- | ext/standard/tests/array/array_pad_variation6.phpt | 672 | ||||
-rw-r--r-- | ext/standard/tests/array/array_pad_variation7.phpt | 127 |
8 files changed, 2451 insertions, 0 deletions
diff --git a/ext/standard/tests/array/array_pad_error.phpt b/ext/standard/tests/array/array_pad_error.phpt new file mode 100644 index 0000000000..63b4c83bf0 --- /dev/null +++ b/ext/standard/tests/array/array_pad_error.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_pad() function : error conditions +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_pad() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_pad() function with Zero arguments --\n"; +var_dump( array_pad() ); + +//Test array_pad with one more than the expected number of arguments +echo "\n-- Testing array_pad() function with more than expected no. of arguments --\n"; +$input = array(1, 2); +$pad_size = 10; +$pad_value = 1; +$extra_arg = 10; +var_dump( array_pad($input, $pad_size, $pad_value, $extra_arg) ); + +// Testing array_pad with less than the expected number of arguments +echo "\n-- Testing array_pad() function with less than expected no. of arguments --\n"; +$input = array(1, 2); +$pad_size = 10; +var_dump( array_pad($input, $pad_size) ); +var_dump( array_pad($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : error conditions *** + +-- Testing array_pad() function with Zero arguments -- + +Warning: array_pad() expects exactly 3 parameters, 0 given in %s on line %d +NULL + +-- Testing array_pad() function with more than expected no. of arguments -- + +Warning: array_pad() expects exactly 3 parameters, 4 given in %s on line %d +NULL + +-- Testing array_pad() function with less than expected no. of arguments -- + +Warning: array_pad() expects exactly 3 parameters, 2 given in %s on line %d +NULL + +Warning: array_pad() expects exactly 3 parameters, 1 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_pad_variation1.phpt b/ext/standard/tests/array/array_pad_variation1.phpt new file mode 100644 index 0000000000..18a7044b3a --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation1.phpt @@ -0,0 +1,270 @@ +--TEST-- +Test array_pad() function : usage variations - unexpected values for 'input' argument +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_pad() function by passing values to $input argument other than arrays +* and see that function outputs proper warning messages wherever expected. +* The $pad_size and $pad_value arguments passed are fixed values. +*/ + +echo "*** Testing array_pad() : passing non array values to \$input argument ***\n"; + +// Initialise $pad_size and $pad_value +$pad_size = 10; +$pad_value = 1; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $input argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_pad() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --"; + var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_size' + var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_size' + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : passing non array values to $input argument *** + +-- Iteration 1 -- +Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- +Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- +Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- +Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- +Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- +Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- +Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- +Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- +Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- +Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- +Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- +Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- +Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- +Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- +Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 19 -- +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- +Warning: array_pad() expects parameter 1 to be array, object given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 22 -- +Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 23 -- +Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- +Warning: array_pad() expects parameter 1 to be array, resource given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, resource given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_pad_variation2.phpt b/ext/standard/tests/array/array_pad_variation2.phpt new file mode 100644 index 0000000000..0267f203bb --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation2.phpt @@ -0,0 +1,256 @@ +--TEST-- +Test array_pad() function : usage variations - unexpected values for 'pad_size' argument(Bug#43482) +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_pad() function by passing values to $pad_size argument other than integers +* and see that function outputs proper warning messages wherever expected. +* The $input and $pad_value arguments passed are fixed values. +*/ + +echo "*** Testing array_pad() : passing non integer values to \$pad_size argument ***\n"; + +// Initialise $input and $pad_value arguments +$input = array(1, 2); +$pad_value = 1; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +//array of values to iterate over +$pad_sizes = array( + + // float data +/*1*/ 10.5, + -10.5, + 12.3456789000e10, + -12.3456789000e10, + 12.3456789000E-10, + .5, + + // array data +/*6*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data +/*11*/ NULL, + null, + + // boolean data +/*13*/ true, + false, + TRUE, + FALSE, + + // empty data +/*17*/ "", + '', + + // string data +/*19*/ "string", + 'string', + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, +); + +// loop through each element of $pad_sizes to check the behavior of array_pad() +$iterator = 1; +foreach($pad_sizes as $pad_size) { + echo "-- Iteration $iterator --\n"; + var_dump( array_pad($input, $pad_size, $pad_value) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : passing non integer values to $pad_size argument *** +-- Iteration 1 -- +array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(1) + [3]=> + int(1) + [4]=> + int(1) + [5]=> + int(1) + [6]=> + int(1) + [7]=> + int(1) + [8]=> + int(1) + [9]=> + int(1) +} +-- Iteration 2 -- +array(10) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) + [3]=> + int(1) + [4]=> + int(1) + [5]=> + int(1) + [6]=> + int(1) + [7]=> + int(1) + [8]=> + int(1) + [9]=> + int(2) +} +-- Iteration 3 -- + +Warning: array_pad(): You may only pad up to 1048576 elements at a time in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: array_pad(): You may only pad up to 1048576 elements at a time in %s on line %d +bool(false) +-- Iteration 5 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 6 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 7 -- + +Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d +NULL +-- Iteration 12 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 13 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 14 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 15 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 16 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 17 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 18 -- + +Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_pad() expects parameter 2 to be long, object given in %s on line %d +NULL +-- Iteration 23 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 24 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/array_pad_variation3.phpt b/ext/standard/tests/array/array_pad_variation3.phpt new file mode 100644 index 0000000000..f7aa025e28 --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation3.phpt @@ -0,0 +1,873 @@ +--TEST-- +Test array_pad() function : usage variations - possible values for 'pad_value' argument +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_pad() function for expected behavior by passing +* different possible values for $pad_value argument. +* $input and $pad_size arguments take fixed value. +*/ + +echo "*** Testing array_pad() : possible values for \$pad_value argument ***\n"; + +// Initialise $input and $pad_size argument +$input = array(1, 2); +$pad_size = 4; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a reference variable +$value = "hello"; +$reference = &$value; + +// different values to be passed to $pad_value argument +$pad_values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // array data +/*10*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data +/*15*/ NULL, + null, + + // boolean data +/*17*/ true, + false, + TRUE, + FALSE, + + // empty data +/*21*/ "", + '', + + // string data +/*23*/ "string", + 'string', + $heredoc, + + // strings with different white spaces +/*26*/ "\v\fHello\t world!! \rstring\n", + '\v\fHello\t world!! \rstring\n', + + // object data +/*28*/ new classA(), + + // undefined data +/*29*/ @$undefined_var, + + // unset data +/*30*/ @$unset_var, + + // resource variable +/*31*/ $fp, + + // reference variable +/*32*/ $reference +); + +// loop through each element of $pad_values to check the behavior of array_pad() +$iterator = 1; +foreach($pad_values as $pad_value) { + echo "-- Iteration $iterator --\n"; + var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_size' + var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_size' + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : possible values for $pad_value argument *** +-- Iteration 1 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(0) + [3]=> + int(0) +} +array(4) { + [0]=> + int(0) + [1]=> + int(0) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 2 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(1) + [3]=> + int(1) +} +array(4) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 3 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(12345) + [3]=> + int(12345) +} +array(4) { + [0]=> + int(12345) + [1]=> + int(12345) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 4 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(-2345) + [3]=> + int(-2345) +} +array(4) { + [0]=> + int(-2345) + [1]=> + int(-2345) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 5 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(10.5) + [3]=> + float(10.5) +} +array(4) { + [0]=> + float(10.5) + [1]=> + float(10.5) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 6 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(-10.5) + [3]=> + float(-10.5) +} +array(4) { + [0]=> + float(-10.5) + [1]=> + float(-10.5) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 7 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(123456789000) + [3]=> + float(123456789000) +} +array(4) { + [0]=> + float(123456789000) + [1]=> + float(123456789000) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 8 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(1.23456789E-9) + [3]=> + float(1.23456789E-9) +} +array(4) { + [0]=> + float(1.23456789E-9) + [1]=> + float(1.23456789E-9) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 9 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(0.5) + [3]=> + float(0.5) +} +array(4) { + [0]=> + float(0.5) + [1]=> + float(0.5) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 10 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(0) { + } + [3]=> + array(0) { + } +} +array(4) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 11 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(1) { + [0]=> + int(0) + } + [3]=> + array(1) { + [0]=> + int(0) + } +} +array(4) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(0) + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 12 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(1) { + [0]=> + int(1) + } + [3]=> + array(1) { + [0]=> + int(1) + } +} +array(4) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(1) + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 13 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [3]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(4) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 14 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [3]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } +} +array(4) { + [0]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [1]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 15 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL + [3]=> + NULL +} +array(4) { + [0]=> + NULL + [1]=> + NULL + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 16 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL + [3]=> + NULL +} +array(4) { + [0]=> + NULL + [1]=> + NULL + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 17 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + bool(true) + [3]=> + bool(true) +} +array(4) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 18 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + bool(false) + [3]=> + bool(false) +} +array(4) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 19 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + bool(true) + [3]=> + bool(true) +} +array(4) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 20 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + bool(false) + [3]=> + bool(false) +} +array(4) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 21 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(0) "" + [3]=> + string(0) "" +} +array(4) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 22 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(0) "" + [3]=> + string(0) "" +} +array(4) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 23 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(6) "string" + [3]=> + string(6) "string" +} +array(4) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 24 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(6) "string" + [3]=> + string(6) "string" +} +array(4) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 25 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(11) "hello world" + [3]=> + string(11) "hello world" +} +array(4) { + [0]=> + string(11) "hello world" + [1]=> + string(11) "hello world" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 26 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(25) "Hello world!! +string +" + [3]=> + string(25) "Hello world!! +string +" +} +array(4) { + [0]=> + string(25) "Hello world!! +string +" + [1]=> + string(25) "Hello world!! +string +" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 27 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(30) "\v\fHello\t world!! \rstring\n" + [3]=> + string(30) "\v\fHello\t world!! \rstring\n" +} +array(4) { + [0]=> + string(30) "\v\fHello\t world!! \rstring\n" + [1]=> + string(30) "\v\fHello\t world!! \rstring\n" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 28 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + object(classA)#%d (0) { + } + [3]=> + object(classA)#%d (0) { + } +} +array(4) { + [0]=> + object(classA)#%d (0) { + } + [1]=> + object(classA)#%d (0) { + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 29 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL + [3]=> + NULL +} +array(4) { + [0]=> + NULL + [1]=> + NULL + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 30 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL + [3]=> + NULL +} +array(4) { + [0]=> + NULL + [1]=> + NULL + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 31 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + resource(%d) of type (stream) + [3]=> + resource(%d) of type (stream) +} +array(4) { + [0]=> + resource(%d) of type (stream) + [1]=> + resource(%d) of type (stream) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 32 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(5) "hello" + [3]=> + string(5) "hello" +} +array(4) { + [0]=> + string(5) "hello" + [1]=> + string(5) "hello" + [2]=> + int(1) + [3]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/array_pad_variation4.phpt b/ext/standard/tests/array/array_pad_variation4.phpt new file mode 100644 index 0000000000..83c1e8300d --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation4.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test array_pad() function : usage variations - binary safe checking +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Passing binary values to $pad_value argument and testing whether +* array_pad() behaves in an expected way with the other arguments passed to the function. +* The $input and $pad_size arguments passed are fixed values. +*/ + +echo "*** Testing array_pad() : Passing binary values to \$pad_value argument ***\n"; + +// initialize the $input and $pad_size argument +$input = array(1, 2, 3); +$pad_size = 6; + +// initialize $pad_value with reference variable +$binary = b"hello"; + +var_dump( array_pad($input, $pad_size, $binary) ); // positive 'pad_size' +var_dump( array_pad($input, -$pad_size, $binary) ); // negative 'pad_size' + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : Passing binary values to $pad_value argument *** +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + string(5) "hello" + [4]=> + string(5) "hello" + [5]=> + string(5) "hello" +} +array(6) { + [0]=> + string(5) "hello" + [1]=> + string(5) "hello" + [2]=> + string(5) "hello" + [3]=> + int(1) + [4]=> + int(2) + [5]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_pad_variation5.phpt b/ext/standard/tests/array/array_pad_variation5.phpt new file mode 100644 index 0000000000..4e8e0f1132 --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation5.phpt @@ -0,0 +1,140 @@ +--TEST-- +Test array_pad() function : usage variations - two dimensional array for 'pad_value' argument +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Passing two dimensional array to $pad_value argument and testing whether +* array_pad() behaves in an expected way with the other arguments passed to the function. +* The $input and $pad_size arguments passed are fixed values. +*/ + +echo "*** Testing array_pad() : Passing 2-d array to \$pad_value argument ***\n"; + +// initialize the $input and $pad_size argument +$input = array(1, 2, 3); +$pad_size = 5; + +// initialize $pad_value +$pad_value = array ( + array(1), + array("hello", 'world'), + array("one" => 1, 'two' => 2) +); + +var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_value' +var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_value' + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : Passing 2-d array to $pad_value argument *** +array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [2]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } + } + [4]=> + array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [2]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } + } +} +array(5) { + [0]=> + array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [2]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } + } + [1]=> + array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [2]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } + } + [2]=> + int(1) + [3]=> + int(2) + [4]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_pad_variation6.phpt b/ext/standard/tests/array/array_pad_variation6.phpt new file mode 100644 index 0000000000..f0f5693a4a --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation6.phpt @@ -0,0 +1,672 @@ +--TEST-- +Test array_pad() function : usage variations - different arrays for 'input' argument +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Passing different arrays to $input argument and testing whether +* array_pad() behaves in an expected way with the other arguments passed to the function. +* The $pad_size and $pad_value arguments passed are fixed values. +*/ + +echo "*** Testing array_pad() : Passing different arrays to \$input argument ***\n"; + +/* Different heredoc strings */ + +// heredoc with blank line +$blank_line = <<<EOT + + +EOT; + +// heredoc with multiline string +$multiline_string = <<<EOT +hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string +EOT; + +// heredoc with diferent whitespaces +$diff_whitespaces = <<<EOT +hello\r world\t +1111\t\t != 2222\v\v +heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces +EOT; + +// heredoc with quoted strings and numeric values +$numeric_string = <<<EOT +11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// different arrays to be passed to $input argument +$inputs = array ( +/*1*/ array(1, 2), // with default keys and numeric values + array(1.1, 2.2), // with default keys & float values + array(false,true), // with default keys and boolean values + array(), // empty array +/*5*/ array(NULL), // with NULL + array("a\v\f", "aaaa\r", "b\tbbb", "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings + array('a\v\f', 'aaaa\r', 'b\tbbb', '\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings + array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $numeric_string), // with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetative keys +/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + +// initialize the $pad_size and $pad_value arguments +$pad_size = 6; +$pad_value = "HELLO"; + +// loop through each sub-array within $inputs to check the behavior of array_pad() +$iterator = 1; +foreach($inputs as $input) { + echo "-- Iteration $iterator --\n"; + var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_size' + var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_size' + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : Passing different arrays to $input argument *** +-- Iteration 1 -- +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + int(1) + [5]=> + int(2) +} +-- Iteration 2 -- +array(6) { + [0]=> + float(1.1) + [1]=> + float(2.2) + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + float(1.1) + [5]=> + float(2.2) +} +-- Iteration 3 -- +array(6) { + [0]=> + bool(false) + [1]=> + bool(true) + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + bool(false) + [5]=> + bool(true) +} +-- Iteration 4 -- +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +-- Iteration 5 -- +array(6) { + [0]=> + NULL + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + NULL +} +-- Iteration 6 -- +array(6) { + [0]=> + string(3) "a" + [1]=> + string(5) "aaaa +" + [2]=> + string(5) "b bbb" + [3]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(3) "a" + [3]=> + string(5) "aaaa +" + [4]=> + string(5) "b bbb" + [5]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" +} +-- Iteration 7 -- +array(6) { + [0]=> + string(5) "a\v\f" + [1]=> + string(6) "aaaa\r" + [2]=> + string(6) "b\tbbb" + [3]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "a\v\f" + [3]=> + string(6) "aaaa\r" + [4]=> + string(6) "b\tbbb" + [5]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" +} +-- Iteration 8 -- +array(6) { + ["h1"]=> + string(1) " +" + ["h2"]=> + string(86) "hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string" + ["h3"]=> + string(88) "hello + world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" + [0]=> + string(90) "11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + ["h1"]=> + string(1) " +" + ["h2"]=> + string(86) "hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string" + ["h3"]=> + string(88) "hello + world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" + [2]=> + string(90) "11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +" +} +-- Iteration 9 -- +array(6) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + [2]=> + string(5) "three" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(3) "one" + [4]=> + string(3) "two" + [5]=> + string(5) "three" +} +-- Iteration 10 -- +array(6) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} +-- Iteration 11 -- +array(6) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(40) + [3]=> + int(30) + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + int(10) + [3]=> + int(20) + [4]=> + int(40) + [5]=> + int(30) +} +-- Iteration 12 -- +array(6) { + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + ["three"]=> + string(6) "thirty" + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + ["three"]=> + string(6) "thirty" +} +-- Iteration 13 -- +array(6) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(4) "four" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + ["one"]=> + int(1) + [3]=> + string(3) "two" + [4]=> + string(4) "four" +} +-- Iteration 14 -- +array(6) { + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL +} +-- Iteration 15 -- +array(6) { + [0]=> + string(4) "true" + [1]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(4) "true" + [3]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +-- Iteration 16 -- +array(6) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +-- Iteration 17 -- +array(6) { + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + NULL + [4]=> + NULL + [5]=> + bool(false) + [6]=> + bool(true) +} +array(6) { + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + NULL + [4]=> + NULL + [5]=> + bool(false) + [6]=> + bool(true) +} +-- Iteration 18 -- +array(6) { + [""]=> + int(4) + [0]=> + int(5) + [1]=> + int(6) + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [""]=> + int(4) + [3]=> + int(5) + [4]=> + int(6) +} +-- Iteration 19 -- +array(6) { + ["One"]=> + int(10) + ["two"]=> + int(20) + ["three"]=> + int(3) + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + ["One"]=> + int(10) + ["two"]=> + int(20) + ["three"]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_pad_variation7.phpt b/ext/standard/tests/array/array_pad_variation7.phpt new file mode 100644 index 0000000000..887f351948 --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation7.phpt @@ -0,0 +1,127 @@ +--TEST-- +Test array_pad() function : usage variations - two dimensional array for 'input' argument +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Passing two dimensional array to $input argument and testing whether +* array_pad() behaves in an expected way with the other arguments passed to the function. +* The $pad_size and $pad_value arguments passed are fixed values. +*/ + +echo "*** Testing array_pad() : Passing 2-D array to \$input argument ***\n"; + +// initialize the 2-d array +$input = array ( + array(1, 2, 3), + array("hello", 'world'), + array("one" => 1, "two" => 2) +); + +// initialize the $pad_size and $pad_value arguments +$pad_size = 5; +$pad_value = "HELLO"; + +// entire 2-d array +echo "-- Entire 2-d array for \$input argument --\n"; +var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_size' +var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_size' + +// sub array +echo "-- Sub array for \$input argument --\n"; +var_dump( array_pad($input[1], $pad_size, $pad_value) ); // positive 'pad_size' +var_dump( array_pad($input[1], -$pad_size, $pad_value) ); // negative 'pad_size' + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : Passing 2-D array to $input argument *** +-- Entire 2-d array for $input argument -- +array(5) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [2]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" +} +array(5) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [3]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [4]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } +} +-- Sub array for $input argument -- +array(5) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" +} +array(5) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "hello" + [4]=> + string(5) "world" +} +Done |