- PHP

How to make PHP array empty

To empty an array, simply override it with an empty array like [] or array().

$array = [];
$array = array();

Example:

<?php 
  $myArray = ['php', 'js', 'java', 'python'];
  print_r($myArray);

  echo '<hr>';

  $myArray = []; // emptying the array
  print_r($myArray);
?>

Output:

Array ( [0] => php [1] => js [2] => java [3] => python )
Array ( )