PHP是否有像jquery $(this)那樣縮短代碼和重複的關鍵字或特性?
例如
// How to avoid typing same variable twice
echo isset($_POST['foo']) ? $_POST['foo'] : '';
jQuery中
<script>
// Avoid typing $("#button-element") again
$("#button-element").click(function() {
$(this).css("border-color", "#000");
});
</script>
但是PHP不是由ECMAScript構建的......?如果你想避免重複,使用[null coalesce operator](https://wiki.php.net/rfc/isset_ternary),即'echo $ _POST ['foo'] ?? '';',但這只是在PHP 7中。 – Terry
你的'this'現在被視爲一個常量,只是你知道「this」;-)你可能正在尋找一個(PHP)OOP'$ this '但很難真正說出你想在這裏實現的目標。 –
在你問這個問題之前,你有沒有試圖研究你的問題?我敢肯定,谷歌會有一些東西......如果不是,那麼這也是「不」的標誌。我真的不明白你想達到什麼或真正的目的... – NewToJS