# Question for working with array? How to loop a sample of 3 items?

There is a section on the website, it displays 3 items and buttons forward/back. There is a common array of IDs of these elements. Then creates a new array of the 3 id, for each other and-download items is already in this array. Forward/back buttons made on ajax and php. Back makes \$i--; forward - \$i++;

An example is the array, arr = ( 0 => 0, 1 = > 1, 2 = > 2, 3 = > 3, 4 = > 4)
There is a variable \$i = 0;
This is its value when the page first loads the browser.
The for loop recording 3 Id. Get a new array arr_new = ( 0 => 0, 1 = > 1, 2 = > 2);
Then click the forward button \$i++, and it needs to work on new and give arr_new = ( 1 = > 1, 2 = > 2, 3 = > 3);
and it should be looped that would be at the end of the array when recording he would have substituted the first value, for example arr_new = ( 4 = > 4, 0 => 0, 1 = > 1);
I wrote something
``````\$i = 5;
\$i_max = count(\$portfolio_id_arr);

for (\$y=0; \$y < 3; \$y++) {
if ( \$i <= \$i_max) {
\$portfolio_id_arr_3el[] += \$portfolio_id_arr[\$i];
\$i++;
} else {
\$i = 0;
}
}``````

and so g**okod
``````\$i = 0;
\$i_max = count(\$portfolio_id_arr);

if ( \$i <= \$i_max) {
\$portfolio_id_arr_3el[] += \$portfolio_id_arr[\$i];
\$i++;
if (\$i <= \$i_max) {
\$portfolio_id_arr_3el[] += \$portfolio_id_arr[\$i];
\$i++;
if (\$i <= \$i_max) {
\$portfolio_id_arr_3el[] += \$portfolio_id_arr[\$i];
\$i++;
} else {
\$i = 0;
}
} else {
\$i = 0;
}
} else {
\$i = 0;
}``````

Actually a question - help mi pliz to get this done, by the way the WordPress site. if that above else, code the screenshots, I skins. I would be very grateful for your help.
July 8th 19 at 16:48