What is the difference between
unset()? I want to hide some elements, I found
unset(), but I don't know which one I should use.
unset() are not same.
hide() is a Drupal function and unset() is a raw php function.
unset() simply destroys a variable.
For an example,
<?php $name = 'Drupal'; unset($name); print $name; // this will result an error as $name is no longer set. `isset()` will return FALSE.
hide() does NOT destroy the variable. It's useful to mark some render-able array is already rendered so it will not be rendered again.
it simply adds/replaces the given argument's
#printed to TRUE so
render() won't execute the theme functions again - instead, it will use cached version if available.
A sample use case of
hide() would be to hide comment form in a node template and show it somewhere else in the template. You will also find it useful when altering pages or blocks. Do NOT
unset() a render array if you want to use it somewhere else.
If you want to hide some specific form element from the user but still want to keep the form structure, set
#access of the element to