Monday 15 February 2010

Combine pairs to groups [PHP / Arrays] -


I have added items to the PHP array Example:

  & lt ;? Php $ element = array ('tiger' = & gt; lion ',' car '= & gt;' bike ',' lion '= & gt;' zoo ',' truck '= & gt;' plane '); ? & Gt;  

Now I want to combine these objects so that all the items connected in any way go to one group. Continuing the example given above:

  & lt ;? Array ('car', 'bike'), 2 = & gt; array ('tiger', 'lion', 'zoo'), 1 = & gt; array (' Do you know how to get it?  

I'm looking for a function Which does this.

  & lt;? $ $ Element = array ('tiger '= & Gt;' lion ',' car '= & gt;' bike ',' lion '=> gt; zoo' 'truck' = 'gt;' plane '); $ groups = array; Forex currency ($ element = $ $ such as value $ & gt; $ val) {$ appended = false; foreach ($ group & $ group) {i F ($ group [0] == $ key) {array_unshift ($ (group $ $) = $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ Array (3) [$ 0] => String (3) "Zoo" [1]   
 

returns:

  array (3) {[0] => = & gt; string (4) "lion" [2] => string (5) "tiger"} [1] = & gt; & Amp; array (2) {[0] => string (4) "bike" [1] => string (3) "car"} [2] = & gt; array (2) {[0] = & Gt; String (5) "plane" [1] = & gt; String (5) "Truck"}}  

No comments:

Post a Comment