Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
#829222
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)
#829223
Hello there, see if the following php test code could help or not? array_merge()
online php sandbox tester you could use: https://sandbox.onlinephpfunctions.com/
so that you could test your php coding online.
Code: Select all
$array1 = array (
    array ( "0" => "7478850075f84c3ca1af2d3082447664", "1" => "John Smith" ),
    array ( "0" => "8823358045f91bebe7b5653087834573", "1" => "Eric Wallace" ));
$array2 = array (
    array ("0" => "", "1" => "Select from List") );
    $result = array_merge($array2, $array1);

//for debug use in below:
    //var_dump($array2);
    //echo json_encode ($result);
    //var_dump($result);
//--output
array(3) {
  [0]=>
  array(2) {
    [0]=>
    string(0) ""
    [1]=>
    string(16) "Select from List"
  }
  [1]=>
  array(2) {
    [0]=>
    string(32) "7478850075f84c3ca1af2d3082447664"
    [1]=>
    string(10) "John Smith"
  }
  [2]=>
  array(2) {
    [0]=>
    string(32) "8823358045f91bebe7b5653087834573"
    [1]=>
    string(12) "Eric Wallace"
  }
#829227
I don't know what keystroke I had wrong last night, but in the light of day, array_unshift DOES work on an array of associative arrays:

function populateOptionsWithGroupUsers($groupName){
$aUsers = PMFGetGroupUsers(PMFGetGroupUID($groupName));
foreach ($aUsers as $key => $user) {
$users[] = array($user["USR_UID"],$user["USR_FIRSTNAME"]." ".$user["USR_LASTNAME"]);
}
array_unshift($users,array("","Select from list"));
return $users;
}

A 1xbet clone script is a pre-designed software so[…]

4rabet clone script is enabling entrepreneurs to e[…]

Parimatch clone script is enabling entrepreneurs t[…]

In the world of cryptocurrency, a wallet is an app[…]