Link to home
Start Free TrialLog in
Avatar of fcqmax
fcqmax

asked on

How to repeat range within an array

Lets say I have an array like this:

$array[]

1.txt
2.txt
3.txt
marker start.txt
4.txt
5.txt
6.txt
7.txt
8.txt
9.txt
marker end.txt
10.txt
11.txt
12.txt
13.txt

How do I repeat the range between the markers and delete the marker rows so $array[] becomes:

1.txt
2.txt
3.txt
4.txt
5.txt
6.txt
7.txt
8.txt
9.txt
4.txt
5.txt
6.txt
7.txt
8.txt
9.txt
10.txt
11.txt
12.txt
13.txt
Avatar of JoachimMartinsen
JoachimMartinsen
Flag of Norway image

This should do it:
<?php
 
function RemoveMarker($ArrayField) {
	if  (stristr(strtolower($ArrayField),"marker") == false) {
		return true;
	}
	return false;
}
 
$OldArray = array("1.txt","2.txt","3.txt","marker start.txt","4.txt","5.txt","6.txt","7.txt","8.txt","9.txt","marker end.txt","10.txt","11.txt","12.txt","13.txt");
 
$NewArray = array_values(array_filter($OldArray,"RemoveMarker"));
 
print_r($NewArray);
 
?>

Open in new window

Avatar of fcqmax
fcqmax

ASKER

Thanks, that part is solved. But still looking for the range between the markers to be repeated.
ASKER CERTIFIED SOLUTION
Avatar of JoachimMartinsen
JoachimMartinsen
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fcqmax

ASKER

Great! Working now!