Can not unset rows of a view programmatically I created a view of terms using views_tree module. I need to remove some of the terms under some conditions. This is my code

function THEME_views_pre_render(&amp;$views) {
    for($i = 0 ; $i &lt; sizeof($views-&gt;result) ; $i++)
       unset($views-&gt;result[$i]);
}


But it still prints all of the terms and doesn't delete any of them. I tried this code

function THEME_views_pre_render(&amp;$views) {
    for($i = 0 ; $i &lt; sizeof($views-&gt;result) ; $i++){
        $views-&gt;result[$i]-&gt;taxonomy_term_data_name ="Hello";
    }
}


It successfully renamed every term, But when I tried the following code, every name turned back to what it was from the beginning and nothing removed.

function THEME_views_pre_render(&amp;$views) {
    for($i = 0 ; $i &lt; sizeof($views-&gt;result) ; $i++){
        $views-&gt;result[$i]-&gt;taxonomy_term_data_name ="Hello";
        unset($views-&gt;result[$i]);
    }
}


How can I remove some terms ?
It should work on template.php too. Module implementation does not look mandatory here.
I have noticed a few issues in the code sample that you have pasted.


There is a typo. It should be $view not $views.
Instead of 

for($i = 0 ; $i &lt; sizeof($view-&gt;result) ; $i++){
}


Do

$sizeof_result = sizeof($view-&gt;result);
for($i = 0 ; $i &lt; $sizeof_result ; $i++)



The following code works for me:

function MYTHEME_views_pre_render(&amp;$view){
  if($view-&gt;name == 'MY_VIEW'){
    $sizeof_result = sizeof($view-&gt;result);
    for($i = 0 ; $i &lt; $sizeof_result ; $i++){
      //IF Condition
        unset($view-&gt;result[$i]);
    } 
  }
}


The reason for using variable $sizeof_result instead of sizeof($view-&gt;result) in for loop is:

For each execution of the loop, the value of sizeof($view->result) changes(decreases by 1). Due to this, the for loops does not work as expected.