<?php $array = [1, 2, 3, 4]; $index = 2; $value = 9; $remains = array_splice($array, max(0, $index - 1)); var_export( array_merge( $array, [$value], $remains ) );
You have javascript disabled. You will not be able to edit any code.