SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jan 2003
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Reomve Value from array...

    Hello,

    I need to remove a "row" from an array. this is how I input the data into the array:

    Code PHP:
      $geoshipping[] = array('id' => $rule->id, 'name' => $rule->name, 'amount' => $rate, 'type' =>$rule->type);

    this is run several times, (each time with different values in $rule).

    I want run delete all the times $rule->type is equal to 'anywhere'

    this is what I tired ,but it didn't really work....i'm a php novice, and well at this point I can' even visualize the array i'm using...so I really need some help:

    Code PHP:
    function uc_geoshipping_anywhere_check($applied_rules) {
        foreach($applied_rules as $check_rules => $type) {
            if($type == 'anywere') {
                unset($applied_rules[$check_rules]);
            }
        }
        $new_array = array_values($applied_rules);
        return $new_array;
    }



    Thanks!
    Idan Arbel
    Arbel Designs
    Email/msn idan@arbel-designs.com
    http://www.arbel-designs.com

  2. #2
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this?
    PHP Code:
    <?php
    function uc_geoshipping_anywhere_check($geoshipping){
        foreach(
    $geoshipping as $key => $array){
            if(
    $array['type'] != 'anywhere'){
                
    $newArray[] = $array
            }
        }
        return 
    $newArray;
    }
    ?>

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    > and well at this point I can' even visualize the array i'm using

    These are probably the most important functions you need to print them out onto the page as you work through your problems.

    print_r($array);
    and
    var_dump($array);

  4. #4
    SitePoint Member
    Join Date
    Jan 2003
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks very much...your tips worked great and I manged to get it work.

    this is a module for ubercart (drupal module) btw.

    Idan
    Idan Arbel
    Arbel Designs
    Email/msn idan@arbel-designs.com
    http://www.arbel-designs.com

  5. #5
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Yay for simple functions.

    PHP Code:
    function clear_type ($a) {

        if (!
    is_array($a)) {
            return 
    $a;
        }

        if (isset(
    $a['type']) && $a['type'] == 'anywhere') {
            unset(
    $a['type']);
        }

        return 
    $a;

    }

    $cleared array_map('clear_type'$dirty); 
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



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
  •