3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ColumnKeyClass { function __toString() { return 'first_name'; } } class IndexKeyClass { function __toString() { return 'id'; } } $column_key = new ColumnKeyClass(); $index_key = new IndexKeyClass(); $records = array( array( 'id' => 2135, 'first_name' => 'John', 'last_name' => 'XXX' ), array( 'id' => 3245, 'first_name' => 'Sally', 'last_name' => 'Smith' )); var_dump($column_key); var_dump($index_key); $firstNames = array_column($records, $column_key, $index_key); print_r($firstNames); var_dump($column_key); var_dump($index_key);
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.6 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
object(ColumnKeyClass)#1 (0) { } object(IndexKeyClass)#2 (0) { } Array ( [2135] => John [3245] => Sally ) object(ColumnKeyClass)#1 (0) { } object(IndexKeyClass)#2 (0) { }
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45
object(ColumnKeyClass)#1 (0) { } object(IndexKeyClass)#2 (0) { } Fatal error: Call to undefined function array_column() in /in/lQqh2 on line 20
Process exited with code 255.
Output for 4.4.5 - 4.4.9
object(columnkeyclass)(0) { } object(indexkeyclass)(0) { } Fatal error: Call to undefined function: array_column() in /in/lQqh2 on line 20
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
object(columnkeyclass)(0) { } object(indexkeyclass)(0) { } Fatal error: Call to undefined function: array_column() in /in/lQqh2 on line 20
Process exited with code 255.
Output for 4.3.0 - 4.3.1
object(columnkeyclass)(0) { } object(indexkeyclass)(0) { } Fatal error: Call to undefined function: array_column() in /in/lQqh2 on line 20

preferences:
149.91 ms | 410 KiB | 5 Q