我知道如何检查数组中的值,但如何在Array Iterator中检查值?
$array = new ArrayIterator(array(
'1QmRjtsw2UQ' => array('pubdate' => '26 Jun 15', 'alt' => '8 Year Old Beautifully Covers Thinking Out Loud', 'anchor text' => '8-yo \'Thinking Out Loud\''),
'eKqLaYrcf3A' => array('pubdate' => '25 Jun 15', 'alt' => 'Plane Lands On Truck', 'anchor text' => 'Plane Lands On Truck'),
));
Run Code Online (Sandbox Code Playgroud)
我正在尝试检查诸如此类的值1QmRjtsw2UQ.
这不起作用:
if(in_array('1QmRjtsw2UQ', $array));
Run Code Online (Sandbox Code Playgroud) 我有这个小的 php 脚本和 htaccess 中的几行,用于将带有查询字符串的 URL 从大写重定向到小写。
但是,仅当 url 文件或 url 的目录部分中有大写字符时,它才会将查询字符串中的大写字符重定向为小写字符。
大写目录示例:
domain.com/JOBS/?position=Java+Developer
Run Code Online (Sandbox Code Playgroud)
将被重定向到
domain.com/jobs/?position=java+developer
Run Code Online (Sandbox Code Playgroud)
目录或文件名中不包含大写字母,但仅在查询字符串中包含大写字母的示例:
domain.com/jobs/?position=Java+Developer
Run Code Online (Sandbox Code Playgroud)
将被重定向到
domain.com/jobs/?position=Java+Developer
Run Code Online (Sandbox Code Playgroud)
第一个示例成功将目录和查询字符串重定向为全部小写。
第二个示例没有将查询字符串重定向为小写,它保持不变。
我不知道要在代码中更改什么以使查询字符串重定向到小写,无论目录或文件名是否大写。
这是代码:
访问
RewriteEngine On
RewriteBase /
# force url to lowercase if upper case is found
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) rewrite-strtolower.php?rewrite-strtolower-url=$1 [QSA,L]
Run Code Online (Sandbox Code Playgroud)
PHP脚本
<?php
if(isset($_GET['rewrite-strtolower-url'])) {
$url = $_GET['rewrite-strtolower-url'];
unset($_GET['rewrite-strtolower-url']);
$params = http_build_query($_GET);
if(strlen($params)) {
$params = '?' . strtolower($params);
}
header('Location: http://' . $_SERVER['HTTP_HOST'] . '/' . strtolower($url) . $params, true, 301);
exit;
}
header("HTTP/1.0 …Run Code Online (Sandbox Code Playgroud) 如果else语句,如何更有效地组合或写入?
如果没有将整个事情写两次,是否有更好的方法来编写它?
唯一的区别是第一部分上的两个条件是检查站点地图是否存在,然后检查站点地图文件修改时间是否在过去24小时内发生了变化.如果这两个条件都为真,那么继续前进,如果这两个条件都是假的,那么移动到语句的else部分,它只是创建xml文档而不检查修改的时间是否已经改变,因为没有要检查的文件.
$time = time();
$sitemap = $_SERVER['DOCUMENT_ROOT'].'/sitemap.xml';
if (file_exists($sitemap)) { // if sitemap exists
if ($time - filemtime($sitemap) >= 1) { // 1 days
$xml = new DomDocument('1.0', 'utf-8');
$xml->formatOutput = true;
// creating base node
$urlset = $xml->createElement('urlset');
$urlset -> appendChild(
new DomAttr('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9')
);
// appending it to document
$xml -> appendChild($urlset);
// building the xml document with your website content
foreach($dirlist as $file) {
if($file['type'] != 'text/x-php') continue;
//Creating single url node
$url = $xml->createElement('url'); …Run Code Online (Sandbox Code Playgroud) 我有2个数组。
第一个数组保存存款金额。
array (
0 => '0.4',
1 => '0.1',
)
Run Code Online (Sandbox Code Playgroud)
第二个数组保存存款日期。
array (
0 => '2019-10-30',
1 => '2019-10-28',
)
Run Code Online (Sandbox Code Playgroud)
我需要像这样组合它们。
array (
0 => '0.4',
1 => '2019-10-30',
2 => '0.1',
3 => '2019-10-28',
)
Run Code Online (Sandbox Code Playgroud)
另外,我怎么也可以像这样将它们结合起来。
array (
0.4 => '2019-10-30',
0.1 => '2019-10-28',
)
Run Code Online (Sandbox Code Playgroud)
我知道这很简单,我今晚一定很累。