Search code examples
phparraysdrupalarray-difference

Using array_diff to remove an item


I am using array_diff to remove an item from an array... It works at removing 'field_home_slider', but the final print render() is outputting like 15 times. Am I missing something as to why the print would do that?

Can this be written a cleaner way? I want item 'field_home_slider' removed from $page['content'];

$array_remove = array_diff($page['content'], array('field_home_slider'));
print render($array_remove);

Original code

print render($page['content']); 

Solution

  • You could try this:

    hide($page['content']['field_home_slider']);
    print render($page['content']);
    

    Here is the reference to the hide() function: https://api.drupal.org/api/drupal/includes!common.inc/function/hide/7