SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist Tapan's Avatar
    Join Date
    May 2005
    Location
    India
    Posts
    564
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post help with array and functions

    Hi,

    I have a function say:

    Code:
    function abc ($agr1, $agr2)
    {
      // do something
    }
    Now i have a page in which i call that function 2 times like:

    Code:
    $test[] = array("1", "2");
    $test[] = array("3", "4");
    abc ("arg1", $test);
    Now function etc. is all workign fine but if i have to re-use the same array then i am not able to empty it. I am using code : unset($test); but it still contains the values etc. How to empty it ?

    Thanks.

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $Test = Array(); 
    Par Exemple:
    PHP Code:
    <?php
    $Test 
    = Array();
    $Test[] = Array(12);
    $Test[] = Array(34);
    Echo 
    '<pre>';
        Echo 
    '<h3>Pre-Reset:</h3>';
            
    Print_R($Test);
        Echo 
    '<h3>Post-Reset:</h3>';
            
    $Test = Array();
            
    Print_R($Test);
    Echo 
    '</pre>';
    ?>
    If you mean that you want to use this inside the function, make the variable a pointer:
    PHP Code:
    Function ABC($ArgumentOne, &$ArgumentTwo){ /* .... */ 
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona


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
  •