arrays - Adding iteration to an objects properties in PHP -
this inelegant problem.
i have returned array of objects this..
array ( [count_assessor0] => stdclass object ( [assessor0] => 91 ) [count_assessor1] => stdclass object ( [assessor1] => 3 ) [count_assessor2] => stdclass object ( [assessor2] => 5 ) [count_assessor3] => stdclass object ( [assessor3] => 24 ) [count_verifier0] => stdclass object ( [verifier0] => 91 ) [count_verifier1] => stdclass object ( [verifier1] => 3 ) [count_verifier2] => stdclass object ( [verifier2] => 5 ) [count_verifier3] => stdclass object ( [verifier3] => 24 ) )
ok, can see each array , property have numerical suffix. want use these suffixes in foreach loop below when comes adding $n objects property error doesn't 'add' suffix on $role.
$options = array('yes - qualified', 'yes - not qualified', 'no - working towards', 'no - not working towards'); $roles = array('assessor' => $options, 'verifier' => $options, 'teaching_status' => $options, 'coaching_status' => $options); $i = 0 ; foreach($roles $role => $options){ echo ucwords($role); $n = 0 ; foreach($options $option) { echo $option ; echo $count["count_$role$i"]->$role$n; $n++ ; $i++ ; endforeach ; unset($n) ; endforeach ;
if have explained enough can help?
thanks!
i think should make use of dynamic variable name creation, described here:
so in code there should that:
$property = ${$role.$n};
echo $count["count_$role$i"]->$property;
Comments
Post a Comment