Coding Villa

Remove or delete elements from array in PHP

Author : nida khawar

Share with Friends
Views : 774
Ratings : 0
Bookmarks : 0
Farourities : 0

Description


In this simple article you will learn that how we remove or delete elements from array in PHP.


Advertisements


 

 

Arrays:

 

 

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

 

 

Syntax:

 

 

$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.

 

 

Code:

 

<?

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

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

 

unset($dogs['X']);

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.

 



Article Tags
Share with Friends

Comments




Leave a Reply

Name (required)  
Mail (will not be published) (required)   
 
Enter This Code
Captcha
 

Advertisements

Article Categories

.NET


Databases


Mobile Development


Operating Systems


Web Development


Coding Villa on Facebook