Unholy Prayer Posted April 22, 2007 Share Posted April 22, 2007 Is it possible to put an IF statement inside an array? I want to display a member's IP adderess but only to admins/moderators and need an if statement to do it. I have the address displayed in a template file in which i have arrays replacing words with strings. I don't want to have any php in the template file so would the following work? 'IP_ADDRESS' => if($perm == 1){ echo "$ip_address"; }, Would that work? If not, I know there are other ways to do it, but I'm not sure what they are. How else could I do this? Link to comment https://forums.phpfreaks.com/topic/48191-if-statements-inside-arrays/ Share on other sites More sharing options...
MadTechie Posted April 22, 2007 Share Posted April 22, 2007 your have to use if on the display or setting it, ie <?php isAdmin = false; $details = array(IP => "11.22.33.44", Name => "MadTechie"); echo $details['Name'].""; echo (isAdmin? "IP:".$details['IP']:"" ?> UNTESTED Link to comment https://forums.phpfreaks.com/topic/48191-if-statements-inside-arrays/#findComment-235576 Share on other sites More sharing options...
Daniel0 Posted April 22, 2007 Share Posted April 22, 2007 'IP_ADDRESS' => $perm==1 ? $ip_address : null, It is using the ternary operator. Link to comment https://forums.phpfreaks.com/topic/48191-if-statements-inside-arrays/#findComment-235600 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.