3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ColumnKeyClass { function __toString() { return 'first_name'; } } class IndexKeyClass { function __toString() { return 'id'; } } class ValueClass { function __toString() { return '2135'; } } $column_key = new ColumnKeyClass(); $index_key = new IndexKeyClass(); $value = new ValueClass(); // Array representing a possible record set returned from a database $records = array( array( 'id' => $value, 'first_name' => 'John', 'last_name' => 'XXX' ), array( 'id' => 3245, 'first_name' => 'Sally', 'last_name' => 'Smith' ), ); var_dump($column_key); var_dump($index_key); var_dump($value); var_dump($records[0]['id']); $firstNames = array_column($records, $column_key, $index_key); print_r($firstNames); var_dump($column_key); var_dump($index_key); var_dump($value); var_dump($records[0]['id']);
Output for 8.3.0 - 8.3.6
object(ColumnKeyClass)#1 (0) { } object(IndexKeyClass)#2 (0) { } object(ValueClass)#3 (0) { } object(ValueClass)#3 (0) { } Fatal error: Uncaught TypeError: Cannot access offset of type ValueClass on array in /in/1uMqh:38 Stack trace: #0 /in/1uMqh(38): array_column(Array, 'first_name', 'id') #1 {main} thrown in /in/1uMqh on line 38
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
object(ColumnKeyClass)#1 (0) { } object(IndexKeyClass)#2 (0) { } object(ValueClass)#3 (0) { } object(ValueClass)#3 (0) { } Fatal error: Uncaught TypeError: Illegal offset type in /in/1uMqh:38 Stack trace: #0 /in/1uMqh(38): array_column(Array, 'first_name', 'id') #1 {main} thrown in /in/1uMqh on line 38
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
object(ColumnKeyClass)#1 (0) { } object(IndexKeyClass)#2 (0) { } object(ValueClass)#3 (0) { } object(ValueClass)#3 (0) { } Array ( [2135] => John [3245] => Sally ) object(ColumnKeyClass)#1 (0) { } object(IndexKeyClass)#2 (0) { } object(ValueClass)#3 (0) { } object(ValueClass)#3 (0) { }
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
object(ColumnKeyClass)#1 (0) { } object(IndexKeyClass)#2 (0) { } object(ValueClass)#3 (0) { } object(ValueClass)#3 (0) { } Array ( [2135] => John [3245] => Sally ) object(ColumnKeyClass)#1 (0) { } object(IndexKeyClass)#2 (0) { } object(ValueClass)#3 (0) { } string(4) "2135"
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) { } object(ValueClass)#3 (0) { } object(ValueClass)#3 (0) { } Fatal error: Call to undefined function array_column() in /in/1uMqh on line 38
Process exited with code 255.
Output for 4.4.5 - 4.4.9
object(columnkeyclass)(0) { } object(indexkeyclass)(0) { } object(valueclass)(0) { } object(valueclass)(0) { } Fatal error: Call to undefined function: array_column() in /in/1uMqh on line 38
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) { } object(valueclass)(0) { } object(valueclass)(0) { } Fatal error: Call to undefined function: array_column() in /in/1uMqh on line 38
Process exited with code 255.
Output for 4.3.0 - 4.3.1
object(columnkeyclass)(0) { } object(indexkeyclass)(0) { } object(valueclass)(0) { } object(valueclass)(0) { } Fatal error: Call to undefined function: array_column() in /in/1uMqh on line 38

preferences:
309.92 ms | 402 KiB | 460 Q