Jump to content


Photo

clear an array


  • Please log in to reply
3 replies to this topic

#1 pluginbaby

pluginbaby
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 16 September 2006 - 04:13 PM

$blabla is an array, like:

$blabla[0]=haha
$blabla[1]=hihi
...

now, is there a function wich I can use to clear the whole array in one time?

so when I use the function, $blabla[0] is empty and also $blabla[1] and so on, in stead of clearing them one by one like: $blabla[0]=""; $blabla[1]=""; ...

is this possible or not?

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 16 September 2006 - 04:20 PM

Just reassign an empty array to the variable:
<?php
$test = array('one','two','three');
echo '<pre>'  . print_r($test,true) . '</pre>';
$test = array();
echo '<pre>'  . print_r($test,true) . '</pre>';
?>

Ken

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 16 September 2006 - 04:21 PM

Use unset or redifine $blablah to have a null value

// unset deletes the variabl $blahBlah
unset($blablah);

// or redifine blabla with a null value, so its not an array anymore
$blablah = '';

Or do what ken says above, redifine blabla as an empty array.

#4 pluginbaby

pluginbaby
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 16 September 2006 - 04:38 PM

thank you, it works now ;D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users