flat file- delete 1 array of multidimentional array

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Andy128
    Major General

    • Dec 2005
    • 2317

    flat file- delete 1 array of multidimentional array

    Lets see if I can explain this. I am able to load elements of a form into a flat file- such as Name, Address, Phone# etc..... Then I load these into a multidimentional array- say $hold, which looks something like this
    $hold[1] => array([0]=>1, [1]=>Frank,[2]=>123 St,[3]=>555-5555)
    $hold[2] => array([0]=>2, [1]=>Kelly, [2]=>111 St,[3]=>111-1111)
    $hold[3] => array([0]=>3, [1]=>Suzie,[2]=>333 St,[3]=>222-2222)

    *the element $hold[1][0] = 1 is simply a way to count records which also corresponds to the exact $hold array so that I can edit elements as seen in the table

    I then load these into a table.

    I can successfully change any specific element but I cannot figure out how to delete say $hold[2].

    Any suggestions?

    Andy
    PHP- is a blast!
  • Watdaflip
    Major General

    • Sep 2005
    • 2116

    #2
    Re: flat file- delete 1 array of multidimentional array

    The only way that I know of (at least can think of, I never needed to delete an array element, so I haven't looked for a built in solution), but I would

    1. find the count - $total_count = count($hold);

    2. overwrite the record in the array with the one after it with a loop
    for($i=$array_num_to_delete; $i < $total_count; $i++)
    {
    $hold[$i] = $hold[($i+1)];
    }

    3. decrement the total
    $total_count--;

    Then write the new array to the file to save it, and the element is removed.

    Note: I just wrote it, so it hasn't been tested, it might not work, if it doesn't ill try to figure something that will work

    Register/Login Script
    Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

    Comment

    • navaldesign
      General & Forum Moderator

      • Oct 2005
      • 12080

      #3
      Re: flat file- delete 1 array of multidimentional array

      Watdaflips solution is correct, however, you should use the $total_count (after reduction by 1) variable and in your save routine have only the first $total_count elements writen, because with the transfer (from index i+1 to index i ) the last two cells of the array will be the same.

      Otherwise, place

      $hold[2] = ""; (if the $hold[2] is the one to be deleted)

      Then, in the Save routine, place a "if" statement to NOT write into the file whichever $hold[] is empty.
      Navaldesign
      Logger Lite: Low Cost, Customizable, multifeatured Login script
      Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
      DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
      Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

      Comment

      • Andy128
        Major General

        • Dec 2005
        • 2317

        #4
        Re: flat file- delete 1 array of multidimentional array

        Watdaflip and Navaldesign-

        Thanks- I will give it a try.

        Andy
        PHP- is a blast!

        Comment

        Working...
        X