PHP Array combine using one column value -


i trying combine 2 arrays 1 common column.but, not getting want. please check below requirement.

array 1

array ( [0] => stdclass object     (         [fieldlabel] => fname         [uuid] => 27478     )  [1] => stdclass object     (         [fieldlabel] => lname         [uuid] => 6103     )  [2] => stdclass object     (         [fieldlabel] => country         [uuid] => 7350     )  [3] => stdclass object     (         [fieldlabel] => check1         [uuid] => 23155     )  [4] => stdclass object     (         [fieldlabel] => radio1         [uuid] => 15664     )    ) 

array 2

 array  ( [0] => stdclass object     (         [uuid] => 27478         [value] => sai1     )  [1] => stdclass object     (         [uuid] => 6103         [value] => sai2     )  [2] => stdclass object     (         [uuid] => 7350         [value] => usa     )  [3] => stdclass object     (         [uuid] => 23155         [value] => usa|india     )    ) 

i need output below. both arrays 'uuid' common. if value not there in second array should empty.

array ( [0] => stdclass object ( [fieldlabel] => fname [uuid] => 27478 [value] =>sai1 )

[1] => stdclass object     (         [fieldlabel] => lname         [uuid] => 6103         [value] =>sai2     )  [2] => stdclass object     (         [fieldlabel] => country         [uuid] => 7350         [value] =>usa     )  [3] => stdclass object     (         [fieldlabel] => check1         [uuid] => 23155         [value] =>usa|india     )  [4] => stdclass object     (         [fieldlabel] => radio1         [uuid] => 15664     )    ) 

please provide suggestions. how can achieve.

you can traverse arrays , make changes below :

foreach ($array1 &$a1val) {    $value = 0;    foreach ($array2 $a2val) {       if($a1val->uuid == $a2val->uuid) {           $value = $a2val->value;           break;        }    }    $a1val->value = $value; } 

p.s. :

  1. & used update $array1 reference.

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -