Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Is this good?

Comments in 'Plugin Development' started by xBeastMode, Apr 15, 2016.

  1. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    Will this clear out a multi-dimensional array index? I just made but didn't test this function.
    Example:
    PHP:
    function clearOutIndexFromMultiArray(array $array$index){
            foreach(
    $array as $res => $ret){
                foreach(
    $ret as $off => $tar) {
                    if(
    $ret[$off] !== $index) continue;
                    unset(
    $ret[$off]);
                    break;
                }
            }
        }
    $array = [];
    $array["fruits"] = [];
    $array["fruits"][] = "apple";
    clearOutFromMultiArray($array"apple");//will that clear out index/offset "apple"?
  2. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    yes but this is better i think
    PHP:
    function clearOutIndexFromMultiArray(array $array$index){
    foreach(
    $array as $res => $ret){
    foreach(
    $ret as $off => $tar) {
    if(
    $tar !== $index) continue; //this line
    unset($ret[$off]);
    break;
    }
    }
    }
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
  4. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
  5. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    Ok nevermind I fixed it.

    PHP:
    function clearOutIndexFromMultiArray(array $array$index){
            foreach(
    $array as $res => $ret){
                foreach(
    $ret as $off => $tar) {
                    if(
    $ret[$off] !== $index) continue;
                    unset(
    $array[$res][$off]);//lol i had to unset from array
                
    }
            }
        }

Share This Page

Advertisement