purencool Posted August 17, 2009 Share Posted August 17, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/170588-solved-deleting-array/ Share on other sites More sharing options...
oni-kun Posted August 17, 2009 Share Posted August 17, 2009 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.. Quote Link to comment https://forums.phpfreaks.com/topic/170588-solved-deleting-array/#findComment-899783 Share on other sites More sharing options...
purencool Posted August 17, 2009 Author Share Posted August 17, 2009 I want to completely remove $value and replace it with $x. Quote Link to comment https://forums.phpfreaks.com/topic/170588-solved-deleting-array/#findComment-899788 Share on other sites More sharing options...
oni-kun Posted August 17, 2009 Share Posted August 17, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/170588-solved-deleting-array/#findComment-899791 Share on other sites More sharing options...
purencool Posted August 17, 2009 Author Share Posted August 17, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/170588-solved-deleting-array/#findComment-899792 Share on other sites More sharing options...
purencool Posted August 17, 2009 Author Share Posted August 17, 2009 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; } Quote Link to comment https://forums.phpfreaks.com/topic/170588-solved-deleting-array/#findComment-899796 Share on other sites More sharing options...
oni-kun Posted August 17, 2009 Share Posted August 17, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/170588-solved-deleting-array/#findComment-899800 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.