It is necessary to remove part of the array. Here is an example of an array:
Array ( [0] => one [1] => two [2] => three [3] => four [4] => five )
The variable can be based on one of the following values in the array. Suggests there is 'three'. Need to take one, two and everything else removed.
Is there any standard methods, or a good solution that would not need to use a loop?
You can use array_splice for that
$input = array("red", "green", "blue", "yellow");
array_splice($input, 1, -1);
// $input is now array("red", "yellow")
If you don't want to use a loop, you could use array_splice.
$input = array("red", "green", "blue", "yellow");
array_splice($input, $varaible, -1);
// $input is now array("red", "yellow")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With