package main
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/route53"
)
func main() {
sess := session.Must(session.NewSession())
client := route53.New(sess)
zones, err := client.ListHostedZones(&route53.ListHostedZonesInput{
MaxItems: aws.String("100"),
})
if err != nil {
fmt.Printf("Error occurred")
}
fmt.Printf("%v", zones)
if zones.IsTruncated {
fmt.Printf("%v", zones.NextMarker)
}
}
Run Code Online (Sandbox Code Playgroud)
由于以下条件,上面的代码失败。
if zones.IsTruncated {
fmt.Printf("%v", zones.NextMarker)
}
Run Code Online (Sandbox Code Playgroud)
结果是
non-bool zones.IsTruncated (type *bool) used as if condition
Run Code Online (Sandbox Code Playgroud)
我想知道的是为什么常规类型(bool)和类型(*bool)之间存在差异。我知道一个是指针值,但是条件应该仍然有用。
这是一个没有条件的输出的尾部片段
IsTruncated: true,
MaxItems: "100",
NextMarker: "Wouldn'tYouLikeToKnow"
}
Run Code Online (Sandbox Code Playgroud) 当我尝试运行composer时,我收到此PHP警告
模块"PDO"已在第0行的"未知"中加载
我想从没有任何数据库的目录中读取 html 文件名。我有一个代码并且它工作正常,但是它给出了两个空白名称,而我在目录中只有 4 个文件。
<?php
if (is_dir('dir')) {
if ($dh = opendir('dir')) {
while (($file = readdir($dh)) !== false) {
echo "filename:".$file."<br />";
}
}
}?>
Run Code Online (Sandbox Code Playgroud)
我有 4 个 html 文件,输出应该是:
filename:aaaaaa kjnnk_13.html
filename:aaaaaa kjnnk_2.html
filename:aaaaaa kjnnk_6.html
filename:aaaaaa kjnnk_9.html
Run Code Online (Sandbox Code Playgroud)
但我发现了 2 个额外的文件名:
filename:.
filename:..
filename:aaaaaa kjnnk_13.html
filename:aaaaaa kjnnk_2.html
filename:aaaaaa kjnnk_6.html
filename:aaaaaa kjnnk_9.html
Run Code Online (Sandbox Code Playgroud)
请帮忙
我们使用一个foreach代码,并且只想显示前3个项目。但是由于某种原因,我们的代码无法正常工作,目前仍显示所有项目。
我在这里想念什么?
码:
<?php $items = $_order->getAllItems(); $i = 0; foreach($items as $i): if($i < 3) {?>
<li class="order-row-item">
<div class="order-row-product">
<div class="order-row-product-image">
<img src="<?php echo $_product = Mage::getModel('catalog/product')->load($i->getProductId())->getSmallImageUrl();?>" border="0" /> </div>
<div class="order-row-product-name">
<?php echo substr($this->escapeHtml($i->getName()), 0, 20) ?>
</div>
</div>
</li>
<?php $i++; } endforeach;?>
Run Code Online (Sandbox Code Playgroud) 我的代码:
class Test {
private $a = 5;
public function __set($name, $value)
{
// TODO: Implement __set() method.
echo $name . "#" .$value."<br>";
}
public static function do_test(){
$x= new Test();
$x->a=5;
}
}
$x=new Test();
$x->a=3;
Test::do_test();
Run Code Online (Sandbox Code Playgroud)
输出:
a#3
Run Code Online (Sandbox Code Playgroud)
函数static do_test()不会调用magic methods(__set).为什么?谢谢!
我正在尝试创建带有评论的帖子页面;但是,当我将评论添加到帖子时它不起作用,因为系统无法识别帖子 ID。我做错了什么,它不知道 post_id 等于 $post_id
我收到以下错误:
SQLSTATE[HY000]: General error: 1364 Field 'post_id' does not have a default value (SQL: insert into
comments(body,updated_at,created_at) values (This is a test comment, 2017-08-15 19:51:47, 2017- 08-15 19:51:47))
意见表
<div class="well">
<h4>Leave a Comment:</h4>
<form role="form" method="post" action="{{ $post->id }}/comments">
{{ csrf_field() }}
<div class="form-group">
<textarea name="body" class="form-control" rows="3"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
路线
Route::post('/posts/{post}/comments', 'CommentController@store');
Run Code Online (Sandbox Code Playgroud)
控制器
public function store(Post $post)
{
$post->addComment(request('body'));
return back(); …Run Code Online (Sandbox Code Playgroud) 我想获取 JSON 解码数组中的最后一个元素,我收到错误
警告:end() 期望参数 1 为数组
$data输出
stdClass Object (
[contact001] => stdClass Object ( [age] => 33 [name] => Robert [tel] => 87778787878787878 )
[contact002] => stdClass Object ( [age] => 33 [name] => Calvin [tel] => 87778787878787878 )
)
Run Code Online (Sandbox Code Playgroud)
PHP代码:
$namejson = $firebase->get(DEFAULT_PATH . '/name/');
$data=json_decode($namejson);
foreach ($data as $key => $value) {
echo end($key);
}
Run Code Online (Sandbox Code Playgroud)
警告:end() 期望参数 1 为数组
我想从$ routes数组中获取匹配路由。如果有多个数组具有相同的“ ur”值。我想全部拿走。
普通数组项看起来像;
[
"controller" => "RegisterController",
"method" => "GET",
"url" => "/register",
"action" => "index"
]
Run Code Online (Sandbox Code Playgroud)
我正在使用我的get_in_array方法获取商品;
$routes = unserialize(apcu_fetch("routes"));
$route = get_in_array($this->url, $routes, "url");
Run Code Online (Sandbox Code Playgroud)
帮手
function get_in_array(string $needle,array $haystack,string $column){
$key = array_search($needle, array_column($haystack, $column));
// even if there are more than one same url, array search returns first one
if (!is_bool($key)){
return $haystack[$key];
}
}
Run Code Online (Sandbox Code Playgroud)
但是array_search()方法只返回第一个匹配项。如果有两个具有相同网址的数组(例如"/register"),则无法同时获取它们。如何获得多个匹配结果?
目前,如果我这样做:
$array1 = [27476, 29173, 24551, 21109, 29754, 19116, 25924, 27406, 26878, 20866, 32889, 25975];
$array2 = [25959, 26427, 26775, 24968, 24501, 27218, 27441, 27353, 25074, 27344, 26794, 25355];
$data = array_merge(
array_merge_recursive(
$array1,
$array2
)
);
Run Code Online (Sandbox Code Playgroud)
我明白了:
array3 = [
0: 25959
1: 26427
2: 26775
3: 24968
4: 24501
5: 27218
6: 27441
7: 27353
8: 25074
9: 27344
10: 26794
11: 25355
12: 27476
13: 29173
14: 24551
15: 21109
16: 29754
17: 19116
18: 25924
19: …Run Code Online (Sandbox Code Playgroud) 我试图在提交表单后重定向到“/”路由(同一页面):
/**
* @Route("/")
*/
Run Code Online (Sandbox Code Playgroud)
我的做法:
return $this->redirectToRoute('/');
Run Code Online (Sandbox Code Playgroud)
给了我以下错误:
无法为命名路由“/”生成 URL,因为此类路由不存在。
php ×9
arrays ×2
laravel ×2
aws-sdk-go ×1
foreach ×1
go ×1
html ×1
laravel-5 ×1
laravel-5.4 ×1
pdo ×1
symfony ×1
symfony-4.4 ×1
symfony4 ×1