问题标签 [isset]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
5 回答
8411 浏览

php - 测试数组键是否存在的最佳方法

想象一下,我想从另一个数组创建一个数组,如下所示:

测试 $array2 是否具有我要传递给另一个数组的索引的最佳方法是什么,而不对我要添加的每个索引使用 if 。

请注意,$array 中的键可以与 $array2 不同

0 投票
4 回答
188 浏览

php - 是否有更好的解决方案来检查许多变量以查看其中一个变量在 PHP 中是否为空?

$_REQUEST[]在一个 php 文件中, or接收到很多变量$_POST[],我必须检查它们,以防它的值null与 function isset(),这很麻烦。有更好的解决方案吗?

0 投票
2 回答
19494 浏览

php - 如果我将 NULL 分配给变量,isset() 会返回 false 吗?

我的意思是...我将其“设置”为NULL。那么isset($somethingNULL) == true

0 投票
3 回答
10823 浏览

php - PHP错误不能在写上下文中使用方法返回>值

我在 PHP 类中收到此错误...

致命错误:无法在第 35 行的 C:\webserver\htdocs\friendproject2\includes\classes\User.class.php 的写入上下文中使用方法返回值

这是麻烦的部分。

此代码在我的委托人中,如果尚未为 $this->session->get('user_id') 设置值,那么它将返回 false 而不是数字。如您所见,我希望检查此值是否为数字,甚至没有设置。

任何有关修复的帮助表示赞赏。

0 投票
1 回答
2072 浏览

javascript - 设置变量后运行 Javascript 函数

我有以下功能:

一旦用户设置了变量:国家服务已经设置,那么我想运行这个函数:

请有人足够友善让我知道如何做到这一点?

谢谢,B。

编辑 - 抱歉忘了说变量来自 onclick's (onClick="flag('scotislands', 'Scottish Islands');")

0 投票
28 回答
958284 浏览

javascript - JavaScript isset() 等效

在 PHP 中你可以做到if(isset($array['foo'])) { ... }。在 JavaScript 中你经常使用if(array.foo) { ... }做同样的事情,但这不是完全一样的陈述。array.foo如果确实存在但为false0(可能还有其他值),该条件也将评估为假。

什么是issetJavaScript 中 PHP 的完美等价物?

在更广泛的意义上,关于 JavaScript 处理不存在的变量、没有值的变量等的通用、完整指南会很方便。


更新:11 年零 11 个月前我发布了这个问题,哇,它仍然有很多活动。现在,我很确定当我写这篇文章时,我只想知道如何检查关联数组(又名字典)中是否存在属性,因此正确的(对我而言)答案涉及hasOwnPropertyin运算符. 我对检查局部或全局变量不感兴趣。

但是,虽然我记得很清楚,但这个意图在所写的问题中并不十分清楚,甚至直接与之相矛盾!我从来没有提到过关联数组,而 PHPisset也可以做其他事情。让这成为我们所有人的一课,了解在问题中正确陈述您的要求是多么重要,以及全局变量、局部变量、对象属性、字典键和你不是 Huey、Dewey、和路易。

与此同时(呵呵),很多人也提供了这个效果的答案,所以对于那些通过谷歌找到这个问题的人来说,我很高兴我的模糊性在某种程度上有所帮助。无论如何,只是想澄清一下。

0 投票
5 回答
2603 浏览

php - isset() 会触发 __get 吗?为什么?

似乎答案是否定的,但为什么呢?

0 投票
3 回答
816 浏览

php - 如果 isset..php/javascript 的操作

当插入评论时,我正在存储一个会话变量.. 称为 user_message .. 我想,当 user_message 已存储时,然后,在 index.php 上显示消息 index.php 现在是:

但是您需要刷新(f5)站点,才能在存储后查看消息。

但是我想如果变量 user_message 已经存储了一些东西,然后显示它..

希望你能理解。

0 投票
4 回答
8517 浏览

php - if isset SESSION 显示 div

我如何在 jquery 中执行检查 isset SESSION user_message 中是否有任何内容,每 1 秒一次,如果有则显示 #box else dont .. 谢谢

0 投票
1 回答
399 浏览

php - How can I get insert query to work with two if(isset statements?

On a users profile, there is a comment box that enables other users to post comments on their profile. I am now working on a dynamic comment area that has a changing text box depending on if A. you are looking at your own profile B. looking at someone elses profile C. not signed in at all.

I am trying to implement "updates" now when you are on your own page, type in the comment box, and it outputs in a designated area on your page. ( going to have it output on a community page but not there yet)

On this profile page, I have the insert query that is inserting regular comments just fine (the first insert query) and now am trying to add a second if(isset statement with a second insert query and am having trouble doing this.

It is not inserting and the page is loading blank after the submit button is hit. I am a newbie with php btw. Thank you: