array combine by array key in php? -


is there function can combine array key ? ( in example pid )

array   0 =>      array       'product' => string 'a product pid 3' (length=9)       'name' => string 'adamramadhan' (length=12)       'pid' => string '3' (length=1)       'timecreate' => string '2011-02-26 13:30:07' (length=19)   1 =>      array       'product' => string 'a product pid 4' (length=8)       'name' => string 'adamramadhan' (length=12)       'pid' => string '4' (length=1)       'timecreate' => string '2011-02-26 13:30:54' (length=19) 

and

array   0 =>      array       'pid' => string '3' (length=1)       'comment' => string 'a comment on pid 3' (length=8)   1 =>      array       'pid' => string '4' (length=1)       'comment' => string 'a comment on pid 4' (length=8)   2 =>      array       'pid' => string '3' (length=1)       'comment' => string 'a comment on pid 3' (length=5)   3 =>      array       'pid' => string '4' (length=1)       'comment' => string 'a comment on pid 4' (length=5)   4 =>      array       'pid' => string '3' (length=1)       'comment' => string 'a comment on pid 3' (length=7)   5 =>      array       'pid' => string '4' (length=1)       'comment' => string 'a comment on pid 4' (length=7)   6 =>      array       'pid' => string '3' (length=1)       'comment' => string 'a comment on pid 3' (length=18)   7 =>      array       'pid' => string '4' (length=1)       'comment' => string 'a comment on pid 4' (length=18) 

to like

array   0 =>      array       'product' => string 'a product pid 3' (length=9)       'name' => string 'adamramadhan' (length=12)       'pid' => string '3' (length=1)       'timecreate' => string '2011-02-26 13:30:07' (length=19)       'comments' => array          0 =>            array             'pid' => string '3' (length=1)             'comment' => string 'a comment on pid 3' (length=8)         2 =>            array             'pid' => string '3' (length=1)             'comment' => string 'a comment on pid 3' (length=5)         4 =>            array             'pid' => string '3' (length=1)             'comment' => string 'a comment on pid 3' (length=7)         6 =>            array             'pid' => string '3' (length=1)             'comment' => string 'a comment on pid 3' (length=18)   1 =>      array       'product' => string 'a product pid 4' (length=8)       'name' => string 'adamramadhan' (length=12)       'pid' => string '4' (length=1)       'timecreate' => string '2011-02-26 13:30:54' (length=19)       'comments' => array          1 =>            array             'pid' => string '4' (length=1)             'comment' => string 'a comment on pid 4' (length=8)         3 =>            array             'pid' => string '4' (length=1)             'comment' => string 'a comment on pid 4' (length=5)         5 =>            array             'pid' => string '4' (length=1)             'comment' => string 'a comment on pid 4' (length=7)         7 =>            array             'pid' => string '4' (length=1)             'comment' => string 'a comment on pid 4' (length=18) 

or no pid on each product comments array ( nested on products array ) ?

thanks looking in.

adam ramadhan

// use pid key foreach ($arr1 $key => $value) {     $arr1_new[$value['pid']] = $value; }  // move comments $arr1_new foreach($arr2 $key => $value) {     $arr2_new[$value['pid']]['comments'][] = $value['comment'];     // $arr2_new[$value['pid']]['comments'][] = $value; // if need information here... }  var_dump($arr2_new); 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -