php - compare two multidimensional arrays of object and set new property true/false pending match on larger set -
i have array of objects example:
larger set:
array( [0] stdclass object( [id] => 1, [name] => monkey, [sub] => ), [1] stdclass object( [id] => 1, [name] => tooth, [sub] => tip ), [2] stdclass object( [id] => 1, [name] => who, [sub] => knows ), )
smaller set
array( [0] stdclass object( [id] => 1, [name] => monkey, [sub] => )
desired out come:
array( [0] stdclass object( [id] => 1, [name] => monkey, [sub] => help, [selected] => yes ), [1] stdclass object( [id] => 1, [name] => tooth, [sub] => tip, [selected] => no ), [2] stdclass object( [id] => 1, [name] => who, [sub] => knows, [selected] => no ), )
so know above horrible example sake of example, , keeping post being mile long bare me. trying play doesn't seem working is
foreach($result_static $stock) { foreach($result_memb $memb_choice) { $stock->selected = "false"; //echo $stock->name .' == '. $memb_choice->name.'<br>'; if($stock->name == $memb_choice->name) { $stock->selected = "yes"; } } $output[] = $stock; }
this doesn't appear matching of actual results, , gather foreach logic off cause either due relooping second loop many times or first 1 withing other way, names each never match respectively way hope.. trying ideas on how better tackle this, , bit more optimized nice, ill take can currently.
try
foreach($result_static $stock) { $stock->selected = "false"; foreach($result_memb $memb_choice) { if($stock->name == $memb_choice->name) { $stock->selected = "yes"; } } $output[] = $stock; }
Comments
Post a Comment