How to prepend a record to the top of an ARRAY of associative arrays?
Posted: Tue May 25, 2021 7:40 pm
Are there any PHP gurus out there who can tell me how to prepend a record to the top of an array of associative arrays?
array_unshift() and array_merge() work on associative arrays, but not on an array of associative arrays.
What I need to do is change this:
Array (
[0] => Array ( [0] => 7478850075f84c3ca1af2d3082447664 [1] => John Smith )
[1] => Array ( [0] => 8823358045f91bebe7b5653087834573 [1] => Eric Wallace ) )
To this:
Array (
[0] => Array ( [0] => [1] => Select from list )
[1] => Array ( [0] => 7478850075f84c3ca1af2d3082447664 [1] => John Smith )
[2] => Array ( [0] => 8823358045f91bebe7b5653087834573 [1] => Eric Wallace ) )
So that Select from list with a value of null is at the top of the list.
Here is the code that generates the original list from records in a PM Group:
function populateOptionsWithGroupUsers($groupName){
$aUsers = PMFGetGroupUsers(PMFGetGroupUID($groupName));
foreach ($aUsers as $key => $user) {
$users[] = array($user["USR_UID"],$user["USR_FIRSTNAME"]." ".$user["USR_LASTNAME"]);
}
return $users;
}
@=departmentHead_Options = populateOptionsWithGroupUsers("Department Head"); (edited)
array_unshift() and array_merge() work on associative arrays, but not on an array of associative arrays.
What I need to do is change this:
Array (
[0] => Array ( [0] => 7478850075f84c3ca1af2d3082447664 [1] => John Smith )
[1] => Array ( [0] => 8823358045f91bebe7b5653087834573 [1] => Eric Wallace ) )
To this:
Array (
[0] => Array ( [0] => [1] => Select from list )
[1] => Array ( [0] => 7478850075f84c3ca1af2d3082447664 [1] => John Smith )
[2] => Array ( [0] => 8823358045f91bebe7b5653087834573 [1] => Eric Wallace ) )
So that Select from list with a value of null is at the top of the list.
Here is the code that generates the original list from records in a PM Group:
function populateOptionsWithGroupUsers($groupName){
$aUsers = PMFGetGroupUsers(PMFGetGroupUID($groupName));
foreach ($aUsers as $key => $user) {
$users[] = array($user["USR_UID"],$user["USR_FIRSTNAME"]." ".$user["USR_LASTNAME"]);
}
return $users;
}
@=departmentHead_Options = populateOptionsWithGroupUsers("Department Head"); (edited)