【php中0,"",null和false的区别】教程文章相关的互联网学习教程文章

php – Symfony Form测试成员函数create()on null【代码】

我正试图测试我的表格.我读到了: 但我得到一个null异常class MediaTypeTest extends TypeTestCase {protected function setUp(){}protected function tearDown(){}// testspublic function testMe(){$formData = array('test' => 'test','test2' => 'test2',);$form = $this->factory->create(MediaType::class);// submit the data to the form directly$form->submit($formData);$this->assertTrue($form->isSynchronized());$t...

php – 为什么实体getter返回null而不是0?【代码】

我在数据库中有一个字段,它是tinyint. 以下是负责此getter的实体的一部分:/*** @var integer** @ORM\Column(name="showAmounts", type="boolean", nullable=false)*/ private $showamounts = 1;/*** Get showamounts** @return integer*/ public function getShowamounts() {return $this->showamounts; }如果showamounts = 0那么echo $o->getShowamounts(); // returns "" instead of "0"当我将getter转换为int时它正在工作,但我...

php – 过滤递归数组并仅删除NULL值【代码】

我想从递归数组中删除所有null或空值但不删除false和0值.function isNotNull($val) {if(is_array($val)) {$ret = array_filter($val, 'isNotNull');return $ret;} else {return (!is_null($val) && $val !== '');}}$arr = array_filter($arr,’isNotNull’); 输入:$arr = array( "stringKey" => "Abc", "boolKey" => false, "zeroKey" => 0, "blankKey" => '', "newArr" => array("stringKey2"=>"Abc2", "boolKey2"=>false, "zero...

php – 将null作为array_keys第二个参数传递【代码】

PHP文档声明default value of array_keys second argument为NULL. 但是,当显式传递NULL时,array_keys似乎无法正常工作. 例: 码$a = array(10=>'a', 11=>'b', 12=>'b', 13=>'c', 14=>'c', 15=>'b');$keys = array_keys($a); var_dump($keys); //Output 0$keys = array_keys($a, null); var_dump($keys); //Output 1产量array0 => int 101 => int 112 => int 123 => int 134 => int 145 => int 15arrayempty题 我估计它必须试图找到...

如何在php中判断变量是null还是未定义【代码】

是否可以创建一个函数来判断变量在PHP中是NULL还是未定义?我将变量传递给函数(如果需要,可以通过引用),但在运行时我不会知道变量的名称. isset()和is_null()不区分NULL和undefined.array_key_exists要求您在编写代码时知道变量的名称.而且我还没有找到一种方法来确定变量的名称而不定义它. 编辑 我也意识到通过引用传递变量会自动定义它. 精 通过收集这些答案和评论,我已经确定我的问题的简短答案是“否”.感谢您的所有输入. 以下...

php – Laravel查询生成器 – 将列设置为NULL【代码】

我正在尝试将我的列更新为NULL但该值作为字符串传递,并将列设置为0而不是null.$update = DB::table('users')->where('id', $primary_key)->update(array($column_name => $new_value));如何确保列更改为NULL?解决方法:请尝试以下方法:$update = DB::table('users')->where('id', $primary_key)->update(array($column_name => Input::has('FormFieldName') ? Input::get('FormFieldName') : null,) );

带有值的PHP数组返回NULL【代码】

我有一个从CSV文件转换而来的数组.我有两个密钥ID和NAME. 如果我显示关键NAME一切正常.但是当我试图获取密钥ID时,我总是得到NULL,但密钥ID有值设置.function convertCsvToArray($filename='', $delimiter=';') {if(!file_exists($filename))return FALSE;$header = NULL;$data = array();if (($handle = fopen($filename, 'r')) !== FALSE){while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE){if(!$header)$header = ...

PHP7:带有标量类型声明的方法拒绝键入juggle NULL值,即使在弱/强制模式下也是如此【代码】

从PHP 7.0开始,标量类型提示int,float,string和bool可以包含在方法签名中.默认情况下,这些类型声明以弱/强制模式(或“type juggling”模式)运行.根据PHP manual:PHP will coerce values of the wrong type into the expected scalar type if possible. For example, a function that is given an integer for a parameter that expects a string will get a variable of type string.但即使可以将NULL强制转换为整数0,具有int typ...

php – 如何知道哪个变量有值,哪个变量为null?【代码】

我需要验证一个输入,我需要稍后检查数据库是否存在于表中.输入必须是手机号码(所有数字,10最大len)或电子邮件地址.以下是我的所作所为<?php$credential = '9999999999';if (ctype_digit($credential)) {$mobile_number = $credential;echo 'Mobile: '. $mobile_number;} elseif (filter_var($credential, FILTER_VALIDATE_EMAIL)) {$email = $credential;echo 'Email: '.$email;}当$credential =’9999999999’时输出;Mobile: 9999...

PHPUnit mocked方法返回null【代码】

我试图使用PHPUnit测试下面的类class stripe extends paymentValidator {public $apiKey;public function __construct ($apiKey){$this->apiKey = $apiKey;}public function charge($token) {try {return $this->requestStripe($token);} catch(\Stripe\Error\Card $e) {echo $e->getMessage();return false;}}public function requestStripe($token) {// do something } }我的测试脚本如下所示:class paymentvalidatorTes...

PHP使用curl抓取网页结果为NULL解决方法【代码】

解决方法:禁用https的加密认证 利用CURLOPT_SSL_VERIFYPEER 和 CURLOPT_SSL_VERIFYHOST 这两个参数来禁用SSL证书的验证 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //禁止 cURL 验证对等证书curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //是否检测服务器的域名与证书上的是否一致

如何使用PHP / MySQLi将NULL插入MySQL整数列?【代码】

我正在通过URL将值传递到PHP页面,并在MySQLi查询中使用它们.问题在于,对于一??个整数列,空字符串实际上会转换为零,而实际上它需要为NULL. 如何通过URL中传递的参数使用PHP / MySQLi将NULL转换为整数列? 更新:这是一个示例,说明如何使用传入参数和准备好的语句进行插入.我需要在数据库上为NULL的那个是$specialtyType.function InsertItem($itemID, $ownerID, $specialtyType) {$this->insertItemStmt->bind_param("ssi", $itemID...

php-MySQL查询中的CONCAT值忽略NULL值【代码】

我想对8个字段(sp,lp,gp,sr,zd,md,pr,rs)中的值进行CONCAT,并将结果返回为“ chemistry”.问题在于,任何一条记录在8种可能的记录中将只有两个(可能是三个或四个)值,其余值将为NULL.此外,如果该值为NULL,则既不显示前面的文本(SP:,LP:,GP:,SR:等),也不显示(换行). 从这里的研究中,我遇到了CONCAT_WS()和IFNULL().我将需要帮助来实现这些功能,以实现所需的结果.CONCAT('SP: ', sp, '<br />','LP: ', lp, '<br />','GP: ', gp, '...

如何在CakePHP中生成MySQL IS NOT NULL条件?【代码】

我正在尝试将结果的子集作为virtualField以便在我的视图中使用.我什至可能无法做到这一点,但是到目前为止,这是我所做的: 我从这个问题开始:CakePHP virtualField find all not null,导致this little beauty. 现在我有一个问题,其中find语句将(Array)传递到MySQL. 我的代码如下:class Transaction extends AppModel { public function __construct($id = false, $table = null, $ds = null) {parent::__construct($id, $table, $...

php中mongodb中的聚合查询返回null【代码】

我在rockmongo工具中运行了此命令及其返回的正确值{ aggregate : "twits", pipeline : [{$group : {_id : "$by", num_tutorial : {$sum : 1}}}] }然后我尝试使用此方法从中提取值define("__COLLECTION_TWITS__","twits");在/var/www/html/TradeTwits/require/config/DBConfig.inc.php中$collectionName=__COLLECTION_TWITS__; $db = $this->connection("mo"); $col = $db->$collec...