algorithm - php, long and deep matrix -


I have a deep and long array (matrix). I only know the product ID, how did the product get the way? Array ([apple] = & gt; array ([new] =

array ([0] = & gt; array ([ID] = & Gt; 1) [1] = & gt; array ([ID] => 2)) [old] => array ([0] => Array ([id] = & gt; 3) [1] => Array ([ID] => 4)))

I have an ID: 3, and I want to get it: apple

You can use this child { $ ($ ID, $ array, and $ keys) {foreach ($ key = $ value = & gt; $ value) {if (is_array ($ value)) {$ result = getById ($ id, $ value, $ key ); If ($ result == true) {$ key = =] = $ key; Back true; }} And if ($ key == 'id' & $ value == $ id) {$ keys [] = $ key; // Optional, the result array returns the ID to correct the returns; } } return false; } // USAGE: $ result_array = array (); GetById (3, $ products, $ result_array); // RESULT (= $ result_array) Array ([0] => ID [1] => [[2] => Old [3] => Apple)

The function will return the error to true and incorrect , the data you want will be stored in the third parameter.

You can use array_reverse () , and reverse the array_pop () , to delete the last item ('id') To


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -