unemployment Posted June 9, 2011 Share Posted June 9, 2011 I'm not sure how to format the 'if (empty($otherfans)' part. What's the cleanest way to do this? $data[0][$k]['message'] = 'You have successfully joined <a href="../c/'.$r['companytag'].'">'.$r['feedfirstname'].'</a> in '.industry($r['industry']).' at '.stage($r['stage']).' stage'.if (empty($otherfans)){"."}; Quote Link to comment https://forums.phpfreaks.com/topic/238873-is-this-syntax-correct/ Share on other sites More sharing options...
fugix Posted June 9, 2011 Share Posted June 9, 2011 in situations like this, i prefer using variable interpolation, like so $data[0][$k]['message'] = 'You have successfully joined <a href="../c/'.$r['companytag'].'">{$r['feedfirstname']}</a> in {industry($r['industry'])} at {stage($r['stage'])} stage{if (empty($otherfans))}.'; Quote Link to comment https://forums.phpfreaks.com/topic/238873-is-this-syntax-correct/#findComment-1227421 Share on other sites More sharing options...
revraz Posted June 9, 2011 Share Posted June 9, 2011 http://php.net/manual/en/function.empty.php Quote Link to comment https://forums.phpfreaks.com/topic/238873-is-this-syntax-correct/#findComment-1227427 Share on other sites More sharing options...
unemployment Posted June 9, 2011 Author Share Posted June 9, 2011 in situations like this, i prefer using variable interpolation, like so $data[0][$k]['message'] = 'You have successfully joined <a href="../c/'.$r['companytag'].'">{$r['feedfirstname']}</a> in {industry($r['industry'])} at {stage($r['stage'])} stage{if (empty($otherfans))}.'; You put the period outside of the if. I need it to say if otherfans is empty then add a period. Is what you did correct? Quote Link to comment https://forums.phpfreaks.com/topic/238873-is-this-syntax-correct/#findComment-1227429 Share on other sites More sharing options...
unemployment Posted June 9, 2011 Author Share Posted June 9, 2011 http://php.net/manual/en/function.empty.php I know the function, just unsure of what the best syntax is. Quote Link to comment https://forums.phpfreaks.com/topic/238873-is-this-syntax-correct/#findComment-1227434 Share on other sites More sharing options...
kenrbnsn Posted June 9, 2011 Share Posted June 9, 2011 You can't put an if statement in a string like that. What are you trying to accomplish? Ken Quote Link to comment https://forums.phpfreaks.com/topic/238873-is-this-syntax-correct/#findComment-1227438 Share on other sites More sharing options...
unemployment Posted June 9, 2011 Author Share Posted June 9, 2011 You can't put an if statement in a string like that. What are you trying to accomplish? Ken At the end of the string I want to add a period if otherfans is empty. Quote Link to comment https://forums.phpfreaks.com/topic/238873-is-this-syntax-correct/#findComment-1227442 Share on other sites More sharing options...
fugix Posted June 9, 2011 Share Posted June 9, 2011 in situations like this, i prefer using variable interpolation, like so $data[0][$k]['message'] = 'You have successfully joined <a href="../c/'.$r['companytag'].'">{$r['feedfirstname']}</a> in {industry($r['industry'])} at {stage($r['stage'])} stage{if (empty($otherfans))}.'; You put the period outside of the if. I need it to say if otherfans is empty then add a period. Is what you did correct? ah, wasnt sure of what you were trying to accomplish.. I believe that instead of placing the if statement inside of your string, before you declare $data[0][$k]['message'], make an if statement with a variable, then simply call the variable in your string..e.g if(empty($otherfans)) { $period = "."; }else { $period = ""; } then simply call the variable at the end of your string. $data[0][$k]['message'] = 'You have successfully joined <a href="../c/'.$r['companytag'].'">{$r['feedfirstname']}</a> in {industry($r['industry'])} at {stage($r['stage'])} stage{$period}'; Quote Link to comment https://forums.phpfreaks.com/topic/238873-is-this-syntax-correct/#findComment-1227457 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.