Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Implement new array function array_column() #56

Closed
wants to merge 12 commits into from

10 participants

@ramsey

array_column() returns the values of the specified column from a multi-dimensional array.

I've actually had this patch sitting around for several years, and I decided to take a look, clean it up, and finally submit it. Inspired by database methods like PDOStatement::fetchColumn(), I wrote this to scratch an itch, since I've often had the need to take a recordset array and pull a single column of values from it, which normally involves looping over the array and creating a new array of the values for the column I want to pull. I decided to implement this in the PHP core to save that step.

You can take a look at the test included to see how it works. The second parameter is the key for the column to return, which can be a number for numeric indexes or a string for associative arrays. If it can't find the column specified, it simply returns an empty array.

ext/standard/array.c
((25 lines not shown))
+ break;
+ case IS_DOUBLE:
+ index = (long)Z_DVAL_P(zoffset);
+ break;
+ case IS_BOOL:
+ case IS_LONG:
+ case IS_RESOURCE:
+ index = Z_LVAL_P(zoffset);
+ break;
+ case IS_STRING:
+ key = Z_STRVAL_P(zoffset);
+ key_len = Z_STRLEN_P(zoffset);
+ break;
+ default:
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "The key should be either a string or an integer");
+ return;
@smalyshev Owner

Maybe RETURN_FALSE ? Though then I'd move the array init after the check.

@ramsey
ramsey added a note

I've updated this to RETURN_FALSE. I've also cleaned it up a bit by removing some of the other cases.

IS_OBJECT should be there too, calling convert_to_string if necessary (will deal with the existence of __toString or not.

convert_to_string_ex afair :)

@ramsey
ramsey added a note

I've added IS_OBJECT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ext/standard/array.c
((40 lines not shown))
+ return;
+ }
+
+ for (zend_hash_internal_pointer_reset_ex(arr_hash, &pointer);
+ zend_hash_get_current_data_ex(arr_hash, (void**)&data, &pointer) == SUCCESS;
+ zend_hash_move_forward_ex(arr_hash, &pointer)) {
+
+ if (Z_TYPE_PP(data) == IS_ARRAY) {
+ if (key && zend_hash_find(Z_ARRVAL_PP(data), key, key_len + 1, (void**)&zvalue) == FAILURE) {
+ continue;
+ } else if (!key && zend_hash_index_find(Z_ARRVAL_PP(data), index, (void**)&zvalue) == FAILURE) {
+ continue;
+ }
+
+ Z_ADDREF_PP(zvalue);
+ zend_hash_next_index_insert(HASH_OF(return_value), (void **)zvalue, sizeof(zval *), NULL);
@nikic Owner
nikic added a note

As you already know that return_value is an array you probably should use Z_ARRVAL_P instead of HASH_OF.

Or even easier just use the add_next_index_zval API function:

add_next_index_zval(return_value, *zvalue);
@ramsey
ramsey added a note

Thanks. I've updated it to use add_next_index_zval().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@cataphract

I'd rather have a more general mechanism for extracting subsets of arrays, like in Mathematica:

In[6]:= {{1, 2}, {3, 4}, {5, 6, 7}}[[All, 2;;]]
Out[6]= {{2}, {4}, {6, 7}}

In[7]:= {{1, 2}, {3, 4}, {5, 6, 7}}[[All, 2]]
Out[7]= {2, 4, 6}

In[8]:= {{1, 2}, {3, 4}, {5, 6, 7}}[[{1,3}, 2]]
Out[8]= {2, 6}

but I guess this is better than nothing.

@ramsey

@cataphract, can you suggest how that might look like PHP? I don't think my implementation is too far off. With some slight modifications, it might be possible to achieve something similar to what you're asking.

@ramsey ramsey Merge branch 'PHP-5.3' into feature/array_column
* PHP-5.3:
  Fix bug 61746 Failing tests in ext/standard/tests/file/windows_links/*
  Fix bug 61720 ext\libxml\tests\bug61367-read.phpt fails
  Fix bug 61719 ext\soap\tests\bugs\bug31422.phpt fails
  Fix bug 61718 ext\ldap\tests\ldap_set_rebind_proc_error.phpt fails
  Fix bug 61717 ext\ldap\tests\ldap_sasl_bind_basic.phpt fails
  Fix bug 61716 tests\basic\021.phpt fails
  Fix bug 61683 tests\basic\bug20539.phpt fails
  Fix bug 61680 ext\zlib\tests\gzencode_variation1-win32.phpt fails
  Fix bug 61676 ext\tidy\tests\bug54682.phpt fails
  Fix bug 61743 tests in ext\standard\tests\file\windows_acls\* fail
b6b91f0
@pierrejoye

@ramsey

btw, pls put a RFC together and send a notification mail to internals once you are ready, referring to this discussion too to avoid to have to discuss everything again from scratch :)

@cataphract

@ramsey You could for instance use null mean both All and to specify a range. This can be sorted out later. For instance, for my examples above:

array_part($foo, [null, [2, null]]);
array_part($foo, [null, 2]);
array_part($foo, [[1, 3], 2]);
@smalyshev
Owner

I think we shouldn't try to boil the ocean here. array_column is very useful on its own. If we will need super-method to do everything and make fresh coffee, we could add it later, but that IMHO should not hold adding array_column.

@dsp
Owner
dsp commented

Yes I agree. I think array_column is good enough to be added. I think we are still waiting for an RFC.

ramsey added some commits
@ramsey ramsey Merge branch 'PHP-5.3' into feature/array_column
* PHP-5.3: (160 commits)
  Remove outdated and user-specific files
  Add NEWS for bug #62262
  Fixed bug RecursiveArrayIterator does not implement Countable
  sync zip ext version with pecl
  one more correction for COM upgrading notes
  split gzgetc_basic.phpt for zlib 1.2.7
  com ext upgrading correction
  com ext upgrading info
  Reverted the BC fix regarding to #57905, test adopted
  Merge PHP 5.3.14 NEWS
  re-add 61755 to NEWS
  Make travis silent
  Adding a test for ext/posix/tests/posix_getegid_basic.phpt
  typo
  improve overflow checks
  fix potential overflow in _php_stream_scandir
  set current versions for libzip and zip ext
  updated NEWS
  zip windows fixes
  fixed bc break related to #57905
  ...
755f220
@ramsey ramsey Cleaning up a memory leak. 5df46d3
@ramsey

I finally got around to creating an RFC and submitting this to internals:

@ccampbell

Hey @ramsey, I think think this proposal is a great idea (I do stuff like this all the time), but how do you feel about extending it slightly.

For example if you start with the following array:

$data = array(
    array('id' => 1, 'name' => 'bob', 'valid' => 1, 'email' => 'bob@yahoo.com'),
    array('id' => 2, 'name' => 'joe', 'valid' => 1, 'email' => 'joe@gmail.com'),
    array('id' => 3, 'name' => 'allison', 'valid' => 1, 'email' => 'allison@gmail.com')
);

Then you do array_column($data, 'name'); it would return

array(
    'bob',
    'joe',
    'allison
)

But what if you could do array_column($data, 'id', 'name', 'email') or array_column($data, ['id', 'name', 'email']) and have that return

array(
    'id' => array(
        1,
        2,
        3
    ),
    'name' => array(
        'bob',
        'joe',
        'allison'
    ),
    'email' => array(
        'bob@yahoo.com',
        'joe@gmail.com',
        'allison@gmail.com'
    )
)

This allows you to basically achieve the same thing but instead of having to make multiple calls you could get a bunch of arrays back in one iteration.

Not sure if this would really hurt performance in which case maybe it could be a separate method called array_columns, but I think it could be useful.

We actually do this at Vimeo quite a bit. Functions like array_multisort require the data in this format.

@Abeja

Hello @ramsey, in my work I often use a similar function, perhaps it will be interesting to you:

function array_collect( $Items , $IndexKey , $ValueKey ) {
    if ( is_null( $IndexKey ) && is_null( $ValueKey ) || !count( $Items ) ) return $Items;
    $Result = array();
    if ( !is_null( $IndexKey ) ) {
        $Keys = is_array( $IndexKey ) ? array_values( $IndexKey ) : array( $IndexKey );
        $Key = ( is_null( end( $Keys ) ) && !array_pop( $Keys ) ) ? '[]' : '';
        $Code = '$Result[ $Item[ $Keys[ ' . implode( '] ] ][ $Item[ $Keys[ ' , array_keys( $Keys ) ) . '] ] ]' . $Key . ' = is_null( $ValueKey ) ? $Item : $Item[ $ValueKey ];';
        foreach ( $Items as $Item ) eval( $Code );
    } else
        foreach ( $Items as $Item ) 
            $Result[] = is_null( $ValueKey ) ? $Item : $Item[ $ValueKey ]; 
    return $Result;                             
}

Examples:

$records = array(
    array( 'id' => 1 , 'parent-id' => 7 , 'name' => 'Doe'),
    array( 'id' => 2 , 'parent-id' => 3 , 'name' => 'Smith'),
    array( 'id' => 4 , 'parent-id' => 7 , 'name' => 'Jones'),
);

array_collect( $records , array( 'parent-id' , 'id' ) , 'name' )
// => array( 7 => array( 1 => 'Doe' , 4 => 'Jones' ), 3 => array( 2 => 'Smith' ) )

array_collect( $records , array( 'parent-id' , null ) , 'name' )
// => array( 7 => array( 'Doe' , 'Jones' ), 3 => array ('Smith' ) )

array_collect( $records , null , 'name' )
// => array( 'Doe' , 'Smith' , 'Jones' )

array_collect( $records , 'id' , null )
/* => 
    array(
        1 => array( 'id' => 1 , 'parent-id' => 7 , 'name' => 'Doe'),
        2 => array( 'id' => 2 , 'parent-id' => 3 , 'name' => 'Smith'),
        4 => array( 'id' => 4 , 'parent-id' => 7 , 'name' => 'Jones'),
    );
*/
@pierrejoye

What's the status of this PR? Are we ready to vote on the RFC?

@ramsey

I need to make some changes, based on feedback.

@lstrojny

@ramsey could you call a vote on internals on this function?

@ramsey

Closing this pull request. It is superseded by pull request #257.

@ramsey ramsey closed this
@Majkl578

@ramsey: Next time, there is no need for new issue, just rebase your branch and force-push it, history will be updated here automatically.

@salathe salathe referenced this pull request from a commit in salathe/php-src
@ramsey ramsey array_column: Cleaning up, as recommended in pull request #56 comments 058b33e
@dsp dsp referenced this pull request from a commit
@dsp dsp Merge branch 'pull-request/257' into PHP-5.5
* pull-request/257:
  array_column: Fix compile-time warnings
  array_column: Removed array_pluck() alias
  array_column: Set array_pluck as an alias for array_column
  array_column: Implement ability to specify an index column
  Cleaning up a memory leak.
  array_column: Adding test for IS_OBJECT and converting object to string
  array_column: Using add_next_index_zval() at nikic's recommendation.
  array_column: Improved tests
  array_column: Cleaning up, as recommended in pull request #56 comments
  Fixing typo in test for array_column()
  Simplify the code and use zend_hash_next_index_insert()
  Adding test for columns not present in all rows for array_column().
  Adding tests for the negative results of array_column()
  Implement new array function array_column()
0173c4b
@dsp dsp referenced this pull request from a commit
@dsp dsp Merge branch 'PHP-5.5'
* PHP-5.5:
  NEWS for array_column
  array_column: Fix compile-time warnings
  array_column: Removed array_pluck() alias
  array_column: Set array_pluck as an alias for array_column
  array_column: Implement ability to specify an index column
  Cleaning up a memory leak.
  array_column: Adding test for IS_OBJECT and converting object to string
  array_column: Using add_next_index_zval() at nikic's recommendation.
  array_column: Improved tests
  array_column: Cleaning up, as recommended in pull request #56 comments
  Fixing typo in test for array_column()
  Simplify the code and use zend_hash_next_index_insert()
  Adding test for columns not present in all rows for array_column().
  Adding tests for the negative results of array_column()
  Implement new array function array_column()
ec26c93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 14, 2012
  1. @ramsey

    Implement new array function array_column()

    ramsey authored
    array_column() returns the values of the specified column from a
    multi-dimensional array.
  2. @ramsey
  3. @ramsey
  4. @ramsey
  5. @ramsey
  6. @ramsey
  7. @ramsey

    array_column: Improved tests

    ramsey authored
  8. @ramsey
Commits on Apr 16, 2012
  1. @ramsey
Commits on Apr 18, 2012
  1. @ramsey

    Merge branch 'PHP-5.3' into feature/array_column

    ramsey authored
    * PHP-5.3:
      Fix bug 61746 Failing tests in ext/standard/tests/file/windows_links/*
      Fix bug 61720 ext\libxml\tests\bug61367-read.phpt fails
      Fix bug 61719 ext\soap\tests\bugs\bug31422.phpt fails
      Fix bug 61718 ext\ldap\tests\ldap_set_rebind_proc_error.phpt fails
      Fix bug 61717 ext\ldap\tests\ldap_sasl_bind_basic.phpt fails
      Fix bug 61716 tests\basic\021.phpt fails
      Fix bug 61683 tests\basic\bug20539.phpt fails
      Fix bug 61680 ext\zlib\tests\gzencode_variation1-win32.phpt fails
      Fix bug 61676 ext\tidy\tests\bug54682.phpt fails
      Fix bug 61743 tests in ext\standard\tests\file\windows_acls\* fail
Commits on Jun 21, 2012
  1. @ramsey

    Merge branch 'PHP-5.3' into feature/array_column

    ramsey authored
    * PHP-5.3: (160 commits)
      Remove outdated and user-specific files
      Add NEWS for bug #62262
      Fixed bug RecursiveArrayIterator does not implement Countable
      sync zip ext version with pecl
      one more correction for COM upgrading notes
      split gzgetc_basic.phpt for zlib 1.2.7
      com ext upgrading correction
      com ext upgrading info
      Reverted the BC fix regarding to #57905, test adopted
      Merge PHP 5.3.14 NEWS
      re-add 61755 to NEWS
      Make travis silent
      Adding a test for ext/posix/tests/posix_getegid_basic.phpt
      typo
      improve overflow checks
      fix potential overflow in _php_stream_scandir
      set current versions for libzip and zip ext
      updated NEWS
      zip windows fixes
      fixed bc break related to #57905
      ...
  2. @ramsey

    Cleaning up a memory leak.

    ramsey authored
This page is out of date. Refresh to see the latest.
View
58 ext/standard/array.c
@@ -2563,6 +2563,64 @@ PHP_FUNCTION(array_count_values)
}
/* }}} */
+/* {{{ proto array array_column(array input, mixed key)
+ Return the values from a single column in the input array, identified by the key */
+PHP_FUNCTION(array_column)
+{
+ zval *zarray, *zoffset, **data, **zvalue;
+ HashTable *arr_hash;
+ HashPosition pointer;
+ long index = 0;
+ char *key = NULL;
+ int key_len = 0;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "az", &zarray, &zoffset) == FAILURE) {
+ return;
+ }
+
+ switch (Z_TYPE_P(zoffset)) {
+ case IS_NULL:
+ index = 0;
+ break;
+ case IS_LONG:
+ index = Z_LVAL_P(zoffset);
+ break;
+ case IS_STRING:
+ key = Z_STRVAL_P(zoffset);
+ key_len = Z_STRLEN_P(zoffset);
+ break;
+ case IS_OBJECT:
+ convert_to_string(zoffset);
+ key = Z_STRVAL_P(zoffset);
+ key_len = Z_STRLEN_P(zoffset);
+ break;
+ default:
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "The key should be either a string or an integer");
+ RETURN_FALSE;
+ }
+
+ arr_hash = Z_ARRVAL_P(zarray);
+ array_init(return_value);
+
+ for (zend_hash_internal_pointer_reset_ex(arr_hash, &pointer);
+ zend_hash_get_current_data_ex(arr_hash, (void**)&data, &pointer) == SUCCESS;
+ zend_hash_move_forward_ex(arr_hash, &pointer)) {
+
+ if (Z_TYPE_PP(data) == IS_ARRAY) {
+ if (key && zend_hash_find(Z_ARRVAL_PP(data), key, key_len + 1, (void**)&zvalue) == FAILURE) {
+ continue;
+ } else if (!key && zend_hash_index_find(Z_ARRVAL_PP(data), index, (void**)&zvalue) == FAILURE) {
+ continue;
+ }
+
+ Z_ADDREF_PP(zvalue);
+ add_next_index_zval(return_value, *zvalue);
+ }
+
+ }
+}
+/* }}} */
+
/* {{{ proto array array_reverse(array input [, bool preserve keys])
Return input as a new array with the order of the entries reversed */
PHP_FUNCTION(array_reverse)
View
6 ext/standard/basic_functions.c
@@ -433,6 +433,11 @@ ZEND_BEGIN_ARG_INFO(arginfo_array_count_values, 0)
ZEND_ARG_INFO(0, arg) /* ARRAY_INFO(0, arg, 0) */
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(arginfo_array_column, 0, 0, 2)
+ ZEND_ARG_INFO(0, arg) /* ARRAY_INFO(0, arg, 0) */
+ ZEND_ARG_INFO(0, key)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO_EX(arginfo_array_reverse, 0, 0, 1)
ZEND_ARG_INFO(0, input) /* ARRAY_INFO(0, arg, 0) */
ZEND_ARG_INFO(0, preserve_keys)
@@ -3299,6 +3304,7 @@ const zend_function_entry basic_functions[] = { /* {{{ */
PHP_FE(array_keys, arginfo_array_keys)
PHP_FE(array_values, arginfo_array_values)
PHP_FE(array_count_values, arginfo_array_count_values)
+ PHP_FE(array_column, arginfo_array_column)
PHP_FE(array_reverse, arginfo_array_reverse)
PHP_FE(array_reduce, arginfo_array_reduce)
PHP_FE(array_pad, arginfo_array_pad)
View
1  ext/standard/php_array.h
@@ -71,6 +71,7 @@ PHP_FUNCTION(array_replace_recursive);
PHP_FUNCTION(array_keys);
PHP_FUNCTION(array_values);
PHP_FUNCTION(array_count_values);
+PHP_FUNCTION(array_column);
PHP_FUNCTION(array_reverse);
PHP_FUNCTION(array_reduce);
PHP_FUNCTION(array_pad);
View
190 ext/standard/tests/array/array_column_basic.phpt
@@ -0,0 +1,190 @@
+--TEST--
+Test array_column() function: basic functionality
+--FILE--
+<?php
+/* Prototype:
+ * array array_column(array $input, mixed $key);
+ * Description:
+ * Returns an array containing all the values from
+ * the specified "column" in a two-dimensional array.
+ */
+
+echo "*** Testing array_column() : basic functionality ***\n";
+/* Array representing a possible record set returned from a database */
+$records = array(
+ array(
+ 'id' => 1,
+ 'first_name' => 'John',
+ 'last_name' => 'Doe'
+ ),
+ array(
+ 'id' => 2,
+ 'first_name' => 'Sally',
+ 'last_name' => 'Smith'
+ ),
+ array(
+ 'id' => 3,
+ 'first_name' => 'Jane',
+ 'last_name' => 'Jones'
+ )
+);
+
+echo "-- first_name column from recordset --\n";
+var_dump(array_column($records, 'first_name'));
+
+echo "-- id column from recordset --\n";
+var_dump(array_column($records, 'id'));
+
+echo "\n*** Testing multiple data types ***\n";
+$file = basename(__FILE__);
+$fh = fopen($file, 'r', true);
+$values = array(
+ array(
+ 'id' => 1,
+ 'value' => new stdClass
+ ),
+ array(
+ 'id' => 2,
+ 'value' => 34.2345
+ ),
+ array(
+ 'id' => 3,
+ 'value' => true
+ ),
+ array(
+ 'id' => 4,
+ 'value' => false
+ ),
+ array(
+ 'id' => 5,
+ 'value' => null
+ ),
+ array(
+ 'id' => 6,
+ 'value' => 1234
+ ),
+ array(
+ 'id' => 7,
+ 'value' => 'Foo'
+ ),
+ array(
+ 'id' => 8,
+ 'value' => $fh
+ )
+);
+var_dump(array_column($values, 'value'));
+
+echo "\n*** Testing numeric column keys ***\n";
+$numericCols = array(
+ array('aaa', '111'),
+ array('bbb', '222'),
+ array('ccc', '333')
+);
+var_dump(array_column($numericCols, 1));
+
+echo "\n*** Testing failure to find specified column ***\n";
+var_dump(array_column($numericCols, 2));
+var_dump(array_column($numericCols, 'foo'));
+
+echo "\n*** Testing single dimensional array ***\n";
+$singleDimension = array('foo', 'bar', 'baz');
+var_dump(array_column($singleDimension, 1));
+
+echo "\n*** Testing columns not present in all rows ***\n";
+$mismatchedColumns = array(
+ array('a' => 'foo', 'b' => 'bar'),
+ array('a' => 'baz', 'c' => 'qux'),
+);
+var_dump(array_column($mismatchedColumns, 'c'));
+
+echo "\n*** Testing use of object converted to string ***\n";
+class Foo
+{
+ public function __toString()
+ {
+ return 'last_name';
+ }
+}
+$f = new Foo();
+var_dump(array_column($records, $f));
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing array_column() : basic functionality ***
+-- first_name column from recordset --
+array(3) {
+ [0]=>
+ string(4) "John"
+ [1]=>
+ string(5) "Sally"
+ [2]=>
+ string(4) "Jane"
+}
+-- id column from recordset --
+array(3) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(2)
+ [2]=>
+ int(3)
+}
+
+*** Testing multiple data types ***
+array(8) {
+ [0]=>
+ object(stdClass)#1 (0) {
+ }
+ [1]=>
+ float(34.2345)
+ [2]=>
+ bool(true)
+ [3]=>
+ bool(false)
+ [4]=>
+ NULL
+ [5]=>
+ int(1234)
+ [6]=>
+ string(3) "Foo"
+ [7]=>
+ resource(5) of type (stream)
+}
+
+*** Testing numeric column keys ***
+array(3) {
+ [0]=>
+ string(3) "111"
+ [1]=>
+ string(3) "222"
+ [2]=>
+ string(3) "333"
+}
+
+*** Testing failure to find specified column ***
+array(0) {
+}
+array(0) {
+}
+
+*** Testing single dimensional array ***
+array(0) {
+}
+
+*** Testing columns not present in all rows ***
+array(1) {
+ [0]=>
+ string(3) "qux"
+}
+
+*** Testing use of object converted to string ***
+array(3) {
+ [0]=>
+ string(3) "Doe"
+ [1]=>
+ string(5) "Smith"
+ [2]=>
+ string(5) "Jones"
+}
+Done
View
82 ext/standard/tests/array/array_column_error.phpt
@@ -0,0 +1,82 @@
+--TEST--
+Test array_column() function: error conditions
+--FILE--
+<?php
+/* Prototype:
+ * array array_column(array $input, mixed $key);
+ * Description:
+ * Returns an array containing all the values from
+ * the specified "column" in a two-dimensional array.
+ */
+
+echo "*** Testing array_column() : error conditions ***\n";
+
+echo "\n-- Testing array_column() function with Zero arguments --\n";
+var_dump(array_column());
+
+echo "\n-- Testing array_column() function with One argument --\n";
+var_dump(array_column(array()));
+
+echo "\n-- Testing array_column() function with more than expected no. of arguments --\n";
+var_dump(array_column(array(), 'foo', 'bar'));
+
+echo "\n-- Testing array_column() function with string as first parameter --\n";
+var_dump(array_column('foo', 0));
+
+echo "\n-- Testing array_column() function with int as first parameter --\n";
+var_dump(array_column(1, 'foo'));
+
+echo "\n-- Testing array_column() key parameter should be a string or an integer (testing bool) --\n";
+var_dump(array_column(array(), true));
+
+echo "\n-- Testing array_column() key parameter should be a string or integer (testing float) --\n";
+var_dump(array_column(array(), 2.3));
+
+echo "\n-- Testing array_column() key parameter should be a string or integer (testing array) --\n";
+var_dump(array_column(array(), array()));
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing array_column() : error conditions ***
+
+-- Testing array_column() function with Zero arguments --
+
+Warning: array_column() expects exactly 2 parameters, 0 given in %s on line %d
+NULL
+
+-- Testing array_column() function with One argument --
+
+Warning: array_column() expects exactly 2 parameters, 1 given in %s on line %d
+NULL
+
+-- Testing array_column() function with more than expected no. of arguments --
+
+Warning: array_column() expects exactly 2 parameters, 3 given in %s on line %d
+NULL
+
+-- Testing array_column() function with string as first parameter --
+
+Warning: array_column() expects parameter 1 to be array, string given in %s on line %d
+NULL
+
+-- Testing array_column() function with int as first parameter --
+
+Warning: array_column() expects parameter 1 to be array, integer given in %s on line %d
+NULL
+
+-- Testing array_column() key parameter should be a string or an integer (testing bool) --
+
+Warning: array_column(): The key should be either a string or an integer in %s on line %d
+bool(false)
+
+-- Testing array_column() key parameter should be a string or integer (testing float) --
+
+Warning: array_column(): The key should be either a string or an integer in %s on line %d
+bool(false)
+
+-- Testing array_column() key parameter should be a string or integer (testing array) --
+
+Warning: array_column(): The key should be either a string or an integer in %s on line %d
+bool(false)
+Done
Something went wrong with that request. Please try again.