removing an element from multidimentional array php -


I'm trying to remove an element from a multi-dimensional array in PHP. Here's the code:

  & lt ;? Php $ tset = "ST3"; $ Gettc = "gettingtc1"; $ Getbid = "gettingbid1"; $ Getresultsid = "MillingId1"; $ User [$ tset] = array (); $ Users [$ tset] [] = array ("testcase" = & gt; "$ gettc", "bilded" = & gt; "$ getbid", "resultsid" => "$ getresultsid"); $ Tset = "TEJ"; $ Gettc = "ggettingtc2"; $ Getbid = "gettingbid2"; $ Getresultsid = "Horserid 2"; $ Users [$ tset] [] = array ("testcase" = & gt; "$ gettc", "bilded" = & gt; "$ getbid", "resultsid" => "$ getresultsid"); $ Tset = "ST3"; $ Gettc = "ggettingtc12"; $ Getbid = "gettingbid13"; $ Getresultsid = "gettigresid14"; $ Users [$ tset] [] = array ("testcase" = & gt; "$ gettc", "bilded" = & gt; "$ getbid", "resultsid" => "$ getresultsid"); Forex currency ($ val => $ yy as dollar) {echo "array for $ val:"; Foreign currency ($ yy $ uy) {echo $ uy ['testcase'] $ Uy ['buildid']. $ Uy ['resultsid']; } Echo & lt; Br> '; } $ Ser = "gettingresid1"; $ To = array_searchRecursive ($ service, $ user); If ($ from <-|>> gt; {print_r ($ to); } Else {resonant "no"; } Function array_searchRecursive ($ Needle, $ Harestack, $ strict = true, $ path = array ()) {if (! Is_array ($ haystack)) {return false; } Forex ($ haystack $ key = & gt; $ val) {if_array ($ val) & amp; Amp; $ Subpath = array_searchRecursive ($ needle, $ val, $ string, $ path)) $ path = array_merge () $ path, array ($ key), $ vice-path); $ Path return; } Otherwise ((! $ Hard & amp; $ val == $ needle) || ($ hard & amp; $ val === $ needle)) {$ path [] = $ key; $ Path return; }     }     return false; }? & Gt;  

Where I'm stuck: Holds the code from $ to in which I have the search element but the result will be the original array of the result $ to Should be removed from $ user .

Any help.

Thank you.

I think you want to use

  $ Users should be removed, which is required to be removed from the array from the unset ($ user [$]);  

But as in $ to elements of the element are instead of a key, what do you want to write your own work to do? .

The function you want is below, and will remove the element of the given array, which will be $ in the address.

  / ** * Keys of $ array * * @ Removes element with elements in the ultimate grass basket, which contains keys and values ​​* @ The ultimate keys to remove the element Define * @ Return new array / function array_remove_bykeys () array $ haystack, array $ keys) {// check that if the element is not found (empty keys ($)) {return $ harestack; } $ Key = array_shift ($ keys); If (is_array ($ haystack [$ key])) {$ haystack [$ key] = array_remove_bykeys ($ haystack [$ key], $ keys); } And if (isset ($ haystack [$ key]) {unset ($ haystack [$ key]); } Return $ Harek; }  

The second method will be to remove all values ​​with the value you searched for.

  / ** * Removes all the elements from the array whose value is $ Sui * @ the ultimate $ haistack, the original array * @ the ultimate $ value to search for the needle * @ value Return a new array with the deleted value / / function array_remove_recursive (array $ hystack, $ needle) {foreach ($ Haystack $ key = & gt; $ value) {if (is_array ($ value)) {$ Haystack [$ key] = array_remove_recursive ($ value, $ needle); } And if ($ value === $ needle) {without set ($ greenstack [$ key]); }} Return of the lost bucks; }  

For completeness (though not recommended as recommended), here is an eval version:

  $ keys = array (...); // key array // $ arr is a variable name that contains the value that you want to remove eval ('unset ($ arr [\'. Implode ('\') [\ '', $ keys]. ' \ ']);');  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -