Use "view" inside a loop / clone a view I'm trying to use a view inside a loop but it's not working,
I'm using "views_get_view($name)" but "clone_view()" / "copy()" is not working, I can't create another reference.

I have a view with a contextual filter and by settings different arguments on each loop with "set_arguments" the result should be different. I get the result for the first loop but all the others are empty.

I'm trying to use something like this:

for($i=2; $i&lt;=4; $i++){

    $view = views_get_view('view_name');
    $view-&gt;set_display($i);
    $view-&gt;set_arguments(array($i));
    $view-&gt;execute();

    dpm($view-&gt;result);
}


and the result is:

... (Array, 4 elements)

... (Array, 0 elements)

... (Array, 0 elements)


The first result is working great (4 elements inside the array) but the others are empty.

I know the above code is not correct as this is not the way to handle objects but at least you will know what I want, a different result for each set of arguments, arguments which are connected to a contextual filter inside view.

Can someone help me with a method to use the view inside a loop ? 
I only managed to generate the result once no mather what.

Thanks.
The $view->set_display($i); will not work unless you have an integer as the display name of your view (which is something I'm not sure if possible or if you need it).

try changing the $i in $view->set_display($i); to the display name of your view:

for($i=2; $i&lt;=4; $i++){

    $view = views_get_view('view_name');
    $view-&gt;set_display('display_name'); //Example: page, page_1, block_1, custom_display_name ..etc
    $view-&gt;set_arguments(array($i));
    $view-&gt;execute();

    dpm($view-&gt;result);
}