Tag: PHP的

这是什么意思在PHP中 – >或=>

可能重复: 我们在php中使用对象操作符“ – >” 参考 – 这个符号在PHP中意味着什么? 我总是用PHP看到这些,但是我不知道它们究竟是什么意思。 什么做->做,做什么=>做。 而且我不是在谈论运营商。 他们是别的东西,但似乎没有人知道…

CakePHP:find哪里的字段不为空

我需要selectUser.site_url不为空的所有行。 在一个普通的MySQL查询中这么做很简单,但是CakePHP是如何完成的呢? 手册提到以下内容: array ("not" => array ( "Post.title" => null ) ) 我已经尝试了以下,但它仍然返回一切 $this->User->find('all', array('conditions' => array('not' => array('User.site_url'))));

检查一个数字是否可以被6个PHP整除

我想检查一个数是否可​​以被6整除,如果不是,我需要增加它,直到可以被整除。 我怎样才能做到这一点 ?

添加“x”小时数

我目前有PHP获取当前时间/date如此: $now = date("Ymd H:m:s"); id喜欢做的是有一个新的variables$new_time等于$now + $hours 。 $hours是24-800的小时数。 有什么build议么?

Laravel更新模型具有唯一的属性validation规则

我有一个laravel User模型,它有一个唯一的username和emailvalidation规则。 在我的知识库中,当我更新模型时,我重新validation这些字段,以便不需要规则validation的问题: public function update($id, $data) { $user = $this->findById($id); $user->fill($data); $this->validate($user->toArray()); $user->save(); return $user; } 这在testing中失败 ValidationException: {"username":["The username has already been taken."],"email":["The email has already been taken."]} 有没有一种方法来优雅地解决这个问题?

如何使用break或在Twig模板中的for循环继续?

我尝试使用一个简单的循环,在我的真实代码中,这个循环更复杂,我需要break这个迭代: {% for post in posts %} {% if post.id == 10 %} {# break #} {% endif %} <h2>{{ post.heading }}</h2> {% endfor %} 我如何使用break行为或在Twig中continue PHP控制结构?

PHP 7 simpleXML

我正在testingPHP7,最近更新后有一个奇怪的问题。 SimpleXML应该默认启用,我的phpinfo页面显示它是可用的: 但是,function不可用: <?php if (function_exists('simplexml_load_file')) { echo "simpleXML functions are available.<br />\n"; } else { echo "simpleXML functions are not available.<br />\n"; } // result– NOT available 并且该模块未列为已加载: ~ $ php -m [PHP Modules] calendar Core ctype curl … Reflection session shmop sockets SPL standard sysvmsg sysvsem sysvshm tokenizer Zend OPcache zlib 任何人都知道是否有这个解决方法? 版本信息: […]

如何使用PHP生成更浅/更深的颜色?

我有一个颜色的hex值,例如#202010 。 如何生成一个新的颜色,在PHP中以百分比(即20%较暗)给出较亮或较暗的颜色 ?

在Laravel迁移文件中填充数据库

我刚刚学习Laravel,并有一个工作迁移文件创build一个用户表。 我正在试图填充用户logging作为迁移的一部分: public function up() { Schema::create('users', function($table){ $table->increments('id'); $table->string('email', 255); $table->string('password', 64); $table->boolean('verified'); $table->string('token', 255); $table->timestamps(); DB::table('users')->insert( array( 'email' => 'name@domain.com', 'verified' => true ) ); }); } 但是运行php artisan migrate时出现以下错误: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'vantage.users' doesn't exist 这显然是因为Artisan还没有创build表格,但是所有的文档似乎都认为有一种使用Fluent Query来迁移数据的方式。 任何人都知道? 谢谢!

PHP读取子目录并循环文件如何?

我需要创build一个循环遍历子目录中的所有文件。 你能帮我结构我的代码是这样的: $main = "MainDirectory"; loop through sub-directories { loop through filels in each sub-directory { do something with each file } }; 你能帮忙吗?