diff --git a/ext/standard/array.c b/ext/standard/array.c index 9a64cf4e052a1..425d53e388a0e 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -2547,6 +2547,9 @@ PHP_FUNCTION(array_column) case IS_LONG: column_idx = Z_LVAL_PP(zcolumn); break; + case IS_DOUBLE: + column_idx = (long)Z_DVAL_PP(zcolumn); + break; case IS_STRING: column = Z_STRVAL_PP(zcolumn); column_len = Z_STRLEN_PP(zcolumn); @@ -2569,6 +2572,9 @@ PHP_FUNCTION(array_column) case IS_LONG: key_idx = Z_LVAL_PP(zkey); break; + case IS_DOUBLE: + key_idx = (long)Z_DVAL_PP(zkey); + break; case IS_STRING: key = Z_STRVAL_PP(zkey); key_len = Z_STRLEN_PP(zkey); diff --git a/ext/standard/tests/array/array_column_basic.phpt b/ext/standard/tests/array/array_column_basic.phpt index 70ce2136b44d2..8c499107d9a30 100644 --- a/ext/standard/tests/array/array_column_basic.phpt +++ b/ext/standard/tests/array/array_column_basic.phpt @@ -42,8 +42,7 @@ echo "-- last_name column from recordset, keyed by value from first_name column var_dump(array_column($records, 'last_name', 'first_name')); echo "\n*** Testing multiple data types ***\n"; -$file = basename(__FILE__); -$fh = fopen($file, 'r', true); +$fh = fopen(__FILE__, 'r', true); $values = array( array( 'id' => 1, @@ -89,11 +88,13 @@ $numericCols = array( ); var_dump(array_column($numericCols, 1)); var_dump(array_column($numericCols, 1, 0)); +var_dump(array_column($numericCols, 1, 0.123)); echo "\n*** Testing failure to find specified column ***\n"; var_dump(array_column($numericCols, 2)); var_dump(array_column($numericCols, 'foo')); var_dump(array_column($numericCols, 0, 'foo')); +var_dump(array_column($numericCols, 3.14)); echo "\n*** Testing single dimensional array ***\n"; $singleDimension = array('foo', 'bar', 'baz'); @@ -230,6 +231,14 @@ array(3) { ["ccc"]=> string(3) "333" } +array(3) { + ["aaa"]=> + string(3) "111" + ["bbb"]=> + string(3) "222" + ["ccc"]=> + string(3) "333" +} *** Testing failure to find specified column *** array(0) { @@ -244,6 +253,8 @@ array(3) { [2]=> string(3) "ccc" } +array(0) { +} *** Testing single dimensional array *** array(0) { diff --git a/ext/standard/tests/array/array_column_error.phpt b/ext/standard/tests/array/array_column_error.phpt index 1aec1acc6364c..bdcbec00627ea 100644 --- a/ext/standard/tests/array/array_column_error.phpt +++ b/ext/standard/tests/array/array_column_error.phpt @@ -26,18 +26,12 @@ var_dump(array_column(1, 'foo')); echo "\n-- Testing array_column() column key parameter should be a string or an integer (testing bool) --\n"; var_dump(array_column(array(), true)); -echo "\n-- Testing array_column() column key parameter should be a string or integer (testing float) --\n"; -var_dump(array_column(array(), 2.3)); - echo "\n-- Testing array_column() column key parameter should be a string or integer (testing array) --\n"; var_dump(array_column(array(), array())); echo "\n-- Testing array_column() index key parameter should be a string or an integer (testing bool) --\n"; var_dump(array_column(array(), 'foo', true)); -echo "\n-- Testing array_column() index key parameter should be a string or integer (testing float) --\n"; -var_dump(array_column(array(), 'foo', 2.3)); - echo "\n-- Testing array_column() index key parameter should be a string or integer (testing array) --\n"; var_dump(array_column(array(), 'foo', array())); @@ -71,11 +65,6 @@ NULL Warning: array_column(): The column key should be either a string or an integer in %s on line %d bool(false) --- Testing array_column() column key parameter should be a string or integer (testing float) -- - -Warning: array_column(): The column key should be either a string or an integer in %s on line %d -bool(false) - -- Testing array_column() column key parameter should be a string or integer (testing array) -- Warning: array_column(): The column key should be either a string or an integer in %s on line %d @@ -86,11 +75,6 @@ bool(false) Warning: array_column(): The index key should be either a string or an integer in %s on line %d bool(false) --- Testing array_column() index key parameter should be a string or integer (testing float) -- - -Warning: array_column(): The index key should be either a string or an integer in %s on line %d -bool(false) - -- Testing array_column() index key parameter should be a string or integer (testing array) -- Warning: array_column(): The index key should be either a string or an integer in %s on line %d