PHP:合并两个数组,同时保留键而不是重新索引?
2022-08-30 06:06:56
如何在保留字符串/int 键的同时合并两个数组(一个包含字符串 = > 值对,另一个具有 int => 值对)?它们都不会重叠(因为一个只有字符串,另一个只有整数)。
这是我当前的代码(这不起作用,因为array_merge正在使用整数键重新索引数组):
// get all id vars by combining the static and dynamic
$staticIdentifications = array(
Users::userID => "USERID",
Users::username => "USERNAME"
);
// get the dynamic vars, formatted: varID => varName
$companyVarIdentifications = CompanyVars::getIdentificationVarsFriendly($_SESSION['companyID']);
// merge the static and dynamic vars (*** BUT KEEP THE INT INDICES ***)
$idVars = array_merge($staticIdentifications, $companyVarIdentifications);