3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $data = [ 'ApplicantDetails_AdditionalApplicantDetails_OtherSurnames_OtherSurname' => [['name' => 'one'], ['name' => 'two']], 'ApplicantDetails_AdditionalApplicantDetails_OtherNames' => [['surname' => 'three', 'forename' => 'forename'],['surname' => 'four']], 'ApplicantDetails_AdditionalApplicantDetails_BirthSurname' => 'birthSurname', 'ApplicantDetails_PresentSurname' => 'presentSurname' ]; $surnameKeys = [ ['ApplicantDetails_AdditionalApplicantDetails_OtherSurnames_OtherSurname', 'name'], ['ApplicantDetails_AdditionalApplicantDetails_OtherNames', 'surname'], 'ApplicantDetails_AdditionalApplicantDetails_BirthSurname', 'ApplicantDetails_PresentSurname' ]; $something = []; array_walk($surnameKeys, function ($keys) use ($data) { var_dump($keys); if (is_array($keys)) { if (isset($data[$keys[0]])) { echo 'here'; $something[] = array_column($data[$keys[0]], $keys[1]); } } }); // array_map(function ($keys) use ($data) { // if (is_array($keys)) { // if (isset($data[$keys[0]])) { // $something[] = array_column($data[$keys[0]], $keys[1]); // continue; // } // } // if (isset($data[$keys])) { // $something[] = $data[$keys]; // } // }, $surnameKeys); var_dump($something); // $uniq = array_unique($something); // var_dump($uniq);
based on hQf4T
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.6
array(2) { [0]=> string(70) "ApplicantDetails_AdditionalApplicantDetails_OtherSurnames_OtherSurname" [1]=> string(4) "name" } herearray(2) { [0]=> string(54) "ApplicantDetails_AdditionalApplicantDetails_OtherNames" [1]=> string(7) "surname" } herestring(56) "ApplicantDetails_AdditionalApplicantDetails_BirthSurname" string(31) "ApplicantDetails_PresentSurname" array(0) { }