Bifalgorithm post · Computer science one · Removing Elements

How does unset() remove elements from a PHP array?

How does unset() remove elements from a PHP array? (Computer science one · Removing Elements) — "You can remove elements from an array using the unset() functi…

Ideas in this flowchart

  • Removing array elements with unset()
  • unset() removes an element from an array
  • Removing an element does not shift the other elements
  • Example of removing an array element
  • $arr = array(10, 20, 30);
  • unset($arr[1]);
  • print_r($arr); displays the resulting array
  • The result is Array ( [0] => 10 [2] => 30 )
  • unset() can also destroy all elements in the array
Feed/

How does unset() remove elements from a PHP array?

No cover

Channel

Computer science one

1 page

"You can remove elements from an array using the unset() function. This function only removes the element from the array, it does not shift other elements down to fill in the unused index.\n\n$arr = array(10, 20, 30);\n\nunset($arr[1]);\n\nprint_r($arr);\n\nThis example would result in the following.\n\nArray ( [0] => 10 [2] => 30 )\n\nFurther, you can use unset() to destroy all elements in the array."

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.