Results 1 to 4 of 4

Thread: flat file- delete 1 array of multidimentional array
      
   

  1. #1
    Join Date
    Dec 2005
    Location
    Michigan
    Posts
    2,317

    Default 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!

  2. #2
    Join Date
    Sep 2005
    Location
    Cincinnati, Ohio
    Posts
    2,116

    Default 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

  3. #3
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,080

    Default 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!


  4. #4
    Join Date
    Dec 2005
    Location
    Michigan
    Posts
    2,317

    Default Re: flat file- delete 1 array of multidimentional array

    Watdaflip and Navaldesign-

    Thanks- I will give it a try.

    Andy
    PHP- is a blast!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

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