SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Ireland
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do you empty an array variable?

    Hi all,

    How do you empty an array variable? Is is a simple as declaring the array as follows:

    //Create the array
    $my_array[] = array(
    "m" => "m",
    "y" => "0",
    "e" => $end
    );
    $my_array[] = array(
    "m" => "m",
    "y" => "0",
    "e" => $end
    );

    //What goes next to make $my_array equal to "", is it?
    $my_array="";

  2. #2
    There is no general chat z0s0's Avatar
    Join Date
    Aug 1998
    Location
    Melbourne
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try
    unset($myarray)
    or
    $myarray = array();
    Wormly Server Performance Monitoring
    Don't wait for an SMS at 4am. Find out what's really
    going on and fix the problem. www.wormly.com/website-monitoring

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    UK
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    unset($my_array);

    but why on earth would you want to do that?

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Ireland
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My reasoning is that I read a full text file into an array and then extract various elements of it into certain variables. Once everything is extracted, the PHP script has many other things to do. However, there is no point in using up CPU memory during this latter phase, hence I want to empty the variable.

    Does this make sense or is it a waste of time?

    Willie

  5. #5
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP is smart, it'll empty it on its own. Are you coming from ASP by any chance?

  6. #6
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Snoozy
    PHP is smart, it'll empty it on its own. Are you coming from ASP by any chance?
    well, yeah, it'll empty it after the script exits, if that's what you mean. but it won't empty it during the script, b/c you might use it still. and he wants to save memory during the rest of the script. that's probably a good idea if it was a large array.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •