CopyPastehas never been so tasty!

Remove or delete elements from array in PHP

by anonymous

  • 0
  • 0
  • 0


 Orignal Source:




Arrays are used to store data just like a variable; a variable store single data but arrays store multiple data. There are three types of array in php.


Numeric Arrays


Associative Arrays


Multi-dimensional Arrays






$cars=array("Saab", “Volvo","BMW","Toyota");     //Numeric arrays

$ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34);   //Associative array



Remove array element in PHP:



To remove array element in php we use built in unset () function that was used for removing a variable in php.  The unset () function takes element as a parameter and remove that element from array.






$dogs = array('A' => 'C', 'B' => 'D','X' => 'Y', 'Q' => 'T');

printf("%s,", var_export($dogs, TRUE));



printf("%s,", var_export($dogs, TRUE));




Above is a simple code to remove an array element using unset () function in php.


This simple article tells that how we can remove an element from arrays in php.



Add A Comment: