3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function array_pluck($key, $input) { if (is_array($key) || !is_array($input)) return array(); $array = array(); foreach($input as $v) { if(array_key_exists($key, $v)) $array[]=$v[$key]; } return array_values($array); } $testArray = array('test' => array('a' => array('percy', 'mitch'), 'b', 'c')); $res = array_pluck('a', $testArray); var_dump($res);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(1) { [0]=> array(2) { [0]=> string(5) "percy" [1]=> string(5) "mitch" } }