简体   繁体   中英

echo $Variable . “word” (only returning $Variable, NOT “word”) -TERNARY Operators

Could it be that I'm missing something very obvious here?

How is it that print ucwords(strtolower($keycode)) . " Preview Page" print ucwords(strtolower($keycode)) . " Preview Page" only returns the $keycode as title, but not the trailing " Preview Page " that's supposed to be there too?

<?php
$title = ((isset($keycode)) ? print ucwords(strtolower($keycode)) . " Preview Page" : print "Home Page"); ?>

<title><?php echo $title; ?></title>

I've even tried print ucwords(strtolower($keycode . ' Preview Page')) just to work it in there, but that didn't change anything. It only seems to see the variable...

Does anybody know how to get this to work? :o) Help please? Thank you for your time.

the problem is that you are echoing the result of a call to print which is just an int I think... Anyway, print and echo both have the effect of outputting the string. You just need to lose the print s so:

$title = ((isset($keycode)) ? ucwords(strtolower($keycode)) . " Preview Page" : "Home Page"); ?>

You're using the operator incorrectly. The result of the first expression determines whether expression 1 or expression 2 is returned to the variable or function it is passed to.

print (isset($keycode)) ? ucwords(strtolower($keycode)) . " Preview Page" : "Home Page"; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM