If you have a flat array containing values with non-digits, and you want to remove these non-digits, you can use various methods.
One approach is to use the
array_splice()
function. Here's an example:
array_splice($milestone, 0, 1); dump($milestone);
In this example, we're using
array_splice()
to remove the first element of the $milestone
array. This should effectively remove any non-digits from the first value in the array.
Another option is to use the
array_values()
function. This function renumbers the array keys, and returns a new array with the renumbered keys. Here's an example:
$milestones = array_values($milestones);
If
$milestones
is a collection, you can use the values()
method to achieve the same result:
$milestones = $milestones->values();
The
values()
method will call array_values()
on your items defined in your collection instance.
Another approach mentioned in the source is using the
str_replace()
function to remove specific characters from the array values. Here's an example:
$milestones = str_replace(array('[', ']', '"'),'',$milestones);
In this example, we're using
str_replace()
to remove square brackets and double quotes from the $milestones
array values. This can be useful if you have values that contain these characters.