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_recursive($surnameKeys, function ($keys) { var_dump($keys); }); // 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 V7vEN
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.0rc3
string(70) "ApplicantDetails_AdditionalApplicantDetails_OtherSurnames_OtherSurname" string(4) "name" string(54) "ApplicantDetails_AdditionalApplicantDetails_OtherNames" string(7) "surname" string(56) "ApplicantDetails_AdditionalApplicantDetails_BirthSurname" string(31) "ApplicantDetails_PresentSurname"