Jump to content

Recommended Posts

hi

 

In the code below I have an array that has nine keys. Two of these keys are text and attached to them is another array. I can search the keys and find the keys that are using strings. I then explode them and print them out. I can get aspect to work just fine. But it is the last step I can get to work.

 

What I want to do is  replace $x with the array that it found is this possible?

                              reset($menuCreation);
                       while (list($key,$value) = each($menuCreation)) {
                               if(is_numeric($key)){
                               }else{
                                   if (is_array($value)){
                                      //insert it back into the array
                                      $x = implode($value);
                                      //array_push($menuCreation, $x );
                                      //unset($value);



                                      echo $x;
                                    }
                               }
                        }
                        //test function

                         print_r ($menuCreation);                        

Link to comment
https://forums.phpfreaks.com/topic/170588-solved-deleting-array/
Share on other sites

Do you mean place $x, the implosion of $value into an array? then something such as this..

reset($menuCreation);
while (list($key,$value) = each($menuCreation)) {
if(!is_numeric($key)){  //! means not, no need for extra else.
    if (is_array($value)){
            //insert it back into the array
            $x = implode($value);
            $menuCreation[1][0] = $x; //second [] is array within array.
            echo $x;
            }
      }
}
//test function
print_r ($menuCreation);

You'd just need to modify which arrays you had([1][0] in my example). It can be set within a function like yours..

I want to completely remove $value and replace it with $x.

 

Like this then?

reset($menuCreation);
while (list($key,$value) = each($menuCreation)) {
if(!is_numeric($key)){  //! means not, no need for extra else.
    if (is_array($value)){
            //insert it back into the array
            $value = implode($value); //Yeah!
            echo $x;
            }
      }
}
//test function
print_r ($menuCreation);

I was think some thing like this.

    reset($menuArray);
    while (list($key,$value) = each($menuArray)) {
        if(!is_numeric($key)) {  //! means not, no need for extra else.
            if (is_array($value)) {
                    //insert it back into the array
                $x = implode($value);
                array_pop($value);
                $menuArray[$key]= $x; //second [] is array within array.
                
            }
        }
    }

 

where the array would be removed and a $x would be replaced

oni-kun  thanks for your help I tried your idea but it would not work but if you point it back to the key it works great. But it was your idea I just refined it =).

The code below fixes the problem.

function ExplodeArrays($menuArray){
    reset($menuArray);
    while (list($key,$value) = each($menuArray)) {
        if(!is_numeric($key)) {  //! means not, no need for extra else.
            if (is_array($value)) {
                $menuArray[$key]= implode($value);
                
            }
        }
    }
  $returnValue = implode($menuArray);
  return $returnValue;
}

oni-kun  thanks for your help I tried your idea but it would not work but if you point it back to the key it works great. But it was your idea I just refined it =).

The code below fixes the problem.

function ExplodeArrays($menuArray){
    reset($menuArray);
    while (list($key,$value) = each($menuArray)) {
        if(!is_numeric($key)) {  //! means not, no need for extra else.
            if (is_array($value)) {
                $menuArray[$key]= implode($value);
                
            }
        }
    }
  $returnValue = implode($menuArray);
  return $returnValue;
}

 

I was gonna write something like that, I started to understand what you meant. Glad I could help!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.