Insert a list of values to defined positions of an array (PHP)

if (!is_array($positionArray) || !is_array($originalArray)) {
 
   return $originalArray;
}
 
foreach ($positionArray as $position => $value) {
 
  // position-1 because array_splice position beginns with 0
  $position = $position > 0 ? $position-1 : $position;
 
  array_splice($originalArray, $position,
               $deleteLength, array($value));
}
 
if ($maxLength > 0) {
 
  return array_slice($originalArray, 0, $maxLength);
}
 
return $originalArray;