Wednesday 15 August 2012

php - Overlapping Associative Arrays -


I need to overlap data from multiple affiliate arrays with the following ideas:

  • If
  • If a key exists but does not match, then add a new value for that element
  • If none is above, then store a value Create element
      & lt; ($ I = 0; $ i & lt; 10; $ i ++) for the php {$ table ["Table_ $ i"] = Array ("cell_0" => Array ('row' = & gt; 12, 'column' = & gt; 5)); } ($ I = 4; $ i & lt; 12; $ i ++) {$ table ["table_ $ i"] = Array ("cell_0" => Array ('row' => 9, 'Column' =) & gt; 8)); } ($ I = 5; $ i & lt; 15; $ i ++) {$ table ["table_ $ i"] = array ("cell_1" = & gt; array ('line' => 4, 'Column' =} & gt; 1)); }? & Gt;   

    The desired output will look like this:

      {"table_0": {"cell_0": {"row": 12, "column": 5} }, "Table_1": {"cell_0": {"line": 12, "column": 5}}, "table_2": {"cell_0": {"row": 12, "column": 5}}, "Table_3": {"cell_0": {"line": 12, "column": 5}}, "table_4": {"cell_0": {"row": 9, "column": 8}} "table_5" {"Cell_0": {"cell_0": {"cell_0": {"cell_0": {8}, "cell_1": {"row": 4, "column": 1}}, "table_6": {"cell_0": {" Line ": {" line ": 4}" column ": {" line " "Table_8": {"cell_0": {"line": 9, "column": 8}, "cell_1": {"row": 4, "column": 1}} "table_9": {"Cell_0": {"row": 9, "column": 8}, "Cell_1": {"line": 4, "column": 1}}, "table_10": {"cell_0": {"row": 9, "column": 8}, "cell_1": {"row" : "," Column_11: {"cell_0": {"row"}: {"row": 9, "column": 8}, "cell_1": {"row": 4, "column": 1 } "": {"Cell_1": {"row_1": {"line": 4, "column": 1}} "table_1": {"cell_1": {"row": 4, "column": 1}}, "Table_14": {"cell_1": {"row": 4, "column": 1}}}   

    Note from the desired output that the value of the price of the cell is not replaced Cell_1: I could not get the desired output by using array_merge () in this case.

    Any help would be appreciated - thanks!

    check array_merge and array_unique php functions.

    No comments:

    Post a Comment