poe Posted October 7, 2007 Share Posted October 7, 2007 can anyone see a better way of doing this... foreach($catAry as $ck => $cv) { $pn = (statCount($ck, 1, 'n') > 0) ? statCount($ck, 1, 'n') : 0; $pp = (statCount($ck, 1, 'y') > 0) ? statCount($ck, 1, 'y') : 0; $gn = (statCount($ck, 2, 'n') > 0) ? statCount($ck, 2, 'n') : 0; $gp = (statCount($ck, 2, 'y') > 0) ? statCount($ck, 2, 'y') : 0; $sn = (statCount($ck, 3, 'n') > 0) ? statCount($ck, 3, 'n') : 0; $sp = (statCount($ck, 3, 'y') > 0) ? statCount($ck, 3, 'y') : 0; $bn = (statCount($ck, 4, 'n') > 0) ? statCount($ck, 4, 'n') : 0; $bp = (statCount($ck, 4, 'y') > 0) ? statCount($ck, 4, 'y') : 0; $poeAry[] = array( 'category' => $cv, 'pn' => $pn, 'pp' => $pp, 'gn' => $gn, 'gp' => $gp, 'sn' => $sn, 'sp' => $sp, 'bn' => $bn, 'bp' => $bp, ); } Link to comment https://forums.phpfreaks.com/topic/72152-shortening-down-some-code/ Share on other sites More sharing options...
Psycho Posted October 7, 2007 Share Posted October 7, 2007 Try this <?php $poeAry[] = array( 'pn' = ((statCount($ck, 1, 'n') > 0) ? statCount($ck, 1, 'n') : 0), 'pp' = ((statCount($ck, 1, 'y') > 0) ? statCount($ck, 1, 'y') : 0), 'gn' = ((statCount($ck, 2, 'n') > 0) ? statCount($ck, 2, 'n') : 0), 'gp' = ((statCount($ck, 2, 'y') > 0) ? statCount($ck, 2, 'y') : 0), 'sn' = ((statCount($ck, 3, 'n') > 0) ? statCount($ck, 3, 'n') : 0), 'sp' = ((statCount($ck, 3, 'y') > 0) ? statCount($ck, 3, 'y') : 0), 'bn' = ((statCount($ck, 4, 'n') > 0) ? statCount($ck, 4, 'n') : 0), 'bp' = ((statCount($ck, 4, 'y') > 0) ? statCount($ck, 4, 'y') : 0) ); ?> Link to comment https://forums.phpfreaks.com/topic/72152-shortening-down-some-code/#findComment-363765 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.