Hey there so I have combined two arrays but I think that's not the right way to do it in PHP. Can you tell me a shorter and better way to do this:
So I have created two arrays called Developers and Projects.
#Creating Developers Array.
$developers = [
'Ammar',
'Waqar',
'Sheraz',
'Suleman',
];
#Creating Project Array.
$projects = [
'Sail Caribe',
'Hacker Craft',
'Jackson Demolition',
'Carribean Yacht Charter',
];
#Adding a name key to Developers Array.
$devNames = [];
foreach($developers as $developer){
$devNames[] = [
'name' => $developer,
];
}
#Adding a project name key to Projects Array.
$projectName = [];
foreach($projects as $project){
$projectName[] = [
'project name' => $project,
];
}
Then I created a function merge_keys to combine the values from two arrays:
#function for merging values of Project and Developers Array.
function merge_keys($array, $key, $array2, $key2){
for ($i=0; $i < sizeof($array); $i++){
$array[$i][$key] = $array[$i][$key];
$array[$i][$key2] = $array2[$i][$key2];
}
return $array;
}
#passing project and developer keys parameters to merge_keys function.
$merged_array = merge_keys($devNames, 'name', $projectName, 'project name');
#displaying the merged array.
echo '<pre>';
print_r($merged_array);