Charles Kozlers Personal Website

Tag: empty array in php

[PHP]Empty an array

by Chuck Kozler on Dec.20, 2009, under Computers, Home, Programming, Web Dev

This simple function will empty an array for you. I had to use this for some stuff I was writing for parsing the results of a MySQL query.

I am surprised that there isnt a built in PHP function for this. If there is, let me know…please!

<?php
 
	function emptyArray( $array )
	{
		$size = sizeof( $array );
		for( $i = 0; $i < $size; $i++ )
		{
			array_pop( $array );
		}
	}
?>

I would use this so that I could use the same array over and over again in a class and have it be dumped every execution of the function it was being utilized in.

Sphere: Related Content

Leave a Comment :, , , , , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...