使用链接器来帮助诊断错误,
大多数现代链接器都包含一个详细的选项,该选项在不同程度上打印出来;
- 链接调用(命令行),
- 链接阶段中包含哪些库的数据,
- 库的位置,
- 所使用的搜索路径。
对于GCC和Clang;您通常会在命令行中添加 -v -wl, - derbose
或 -v -wl,-v
。可以在此处找到更多细节;
- linux ld man page 。
- llvm 链接器页面。
- “ GCC的简介” 第9章。
对于MSVC,/verbose
(特别是/verbose:lib
)被添加到链接命令行。
Intro
首先您有一个字符串。 JSON不是数组,对象或数据结构。 json 是一种基于文本的序列化格式 - 所以一个花式字符串,但仍然只是一个字符串。使用 json_decode()
将其解码。
$data = json_decode($json);
在其中您可能会发现:
这些是JSON中可以编码的内容。或更准确地说,这些是可以在JSON中编码的事物的PHP版本。
他们没有什么特别的。它们不是“ JSON对象”或“ JSON数组”。您已经解码了JSON-您现在拥有基本的日常php类型。
对象将是 stdclass 的实例a href =“ https://stackoverflow.com/questions/931407/what-is-stdclass-in-php”> generic事情这并不重要。
访问对象属性
您访问 properties 这些对象之一与任何其他对象的公共非静态属性相同,例如 $ object->属性
。
$json = '
{
"type": "donut",
"name": "Cake"
}';
$yummy = json_decode($json);
echo $yummy->type; //donut
访问阵列元素
您以其他任何数组的方式访问其中一个阵列的元素,例如。 rel =“ noreferrer”> $ array [0]
。
$json = '
[
"Glazed",
"Chocolate with Sprinkles",
"Maple"
]';
$toppings = json_decode($json);
echo $toppings[1]; //Chocolate with Sprinkles
用 foreach
迭代。
foreach ($toppings as $topping) {
echo $topping, "\n";
}
玻璃
撒巧克力
枫
内置阵列函数。
访问嵌套项目
对象的属性和数组的元素可能是更多对象和/或数组 - 您只需继续像往常一样继续访问其属性和成员,例如 $ object->数组[0] - > etc
。
$json = '
{
"type": "donut",
"name": "Cake",
"toppings": [
{ "id": "5002", "type": "Glazed" },
{ "id": "5006", "type": "Chocolate with Sprinkles" },
{ "id": "5004", "type": "Maple" }
]
}';
$yummy = json_decode($json);
echo $yummy->toppings[2]->id; //5004
传递 true
作为第二个参数to json_decode()
您要这样做,而不是对象,您将获得关联数组 - 带有键字符串的数组。同样,您像往常一样访问其元素,例如 $ array ['key']
。
$json = '
{
"type": "donut",
"name": "Cake",
"toppings": [
{ "id": "5002", "type": "Glazed" },
{ "id": "5006", "type": "Chocolate with Sprinkles" },
{ "id": "5004", "type": "Maple" }
]
}';
$yummy = json_decode($json, true);
echo $yummy['toppings'][2]['type']; //Maple
访问关联数组项目
$json = '
{
"foo": "foo value",
"bar": "bar value",
"baz": "baz value"
}';
$assoc = json_decode($json, true);
foreach ($assoc as $key => $value) {
echo "The value of key '$key' is '$value'", PHP_EOL;
}
语法
键'foo'的值是'foo value'
关键“ bar”的值是“ bar value”
密钥“ baz”的价值是“ baz value'
不知道如何构建数据
读取文档,无论您从中获得了json。
查看JSON-您可以看到Curly Brackets {}
期望对象,您可以看到Square Brackets []
期望一个数组。
用a print_r()
$json = '
{
"type": "donut",
"name": "Cake",
"toppings": [
{ "id": "5002", "type": "Glazed" },
{ "id": "5006", "type": "Chocolate with Sprinkles" },
{ "id": "5004", "type": "Maple" }
]
}';
$yummy = json_decode($json);
print_r($yummy);
stdClass Object
(
[type] => donut
[name] => Cake
[toppings] => Array
(
[0] => stdClass Object
(
[id] => 5002
[type] => Glazed
)
[1] => stdClass Object
(
[id] => 5006
[type] => Chocolate with Sprinkles
)
[2] => stdClass Object
(
[id] => 5004
[type] => Maple
)
)
)
:告诉您您有对象的位置,有数组的位置以及其成员的名称和值。
如果您只能在迷路之前就已经走得太远了,请走那么远,然后用 print_r()
击中:
print_r($yummy->toppings[0]);
stdClass Object
(
[id] => 5002
[type] => Glazed
)
将问题分解成更容易缠绕头的碎片。
json_decode()
返回 null
这发生了,因为要么:
- JSON完全由此组成,
null
。 - JSON无效 - 检查
JSON_LAST_ERROR_MSG
或通过 jsonlint 。
- 它包含嵌套超过512级深的元素。可以通过将整数作为第三个参数传递给
json_decode() >。
如果您需要更改最大深度,则可能解决了错误的问题。找出为什么您要获得如此深厚的数据(例如,您要查询的正在生成JSON的服务有一个错误),并使其不发生。
对象属性名称包含一个特殊字符
有时您会有一个包含连字符> -
或在sign @code>@的对象属性名称在字面标识符中使用。相反,您可以在卷曲括号中使用字符串文字来解决它。
$json = '{"@attributes":{"answer":42}}';
$thing = json_decode($json);
echo $thing->{'@attributes'}->answer; //42
如果您有一个整数作为属性,请参见:如何访问对象属性名称像整数一样?作为参考。
有人将JSON放入您的JSON
这很荒谬,但发生了 - JSON在您的JSON中编码为字符串。解码,像往常一样访问字符串,解码 ,并最终达到您需要的内容。
$json = '
{
"type": "donut",
"name": "Cake",
"toppings": "[{ \"type\": \"Glazed\" }, { \"type\": \"Maple\" }]"
}';
$yummy = json_decode($json);
$toppings = json_decode($yummy->toppings);
echo $toppings[0]->type; //Glazed
数据不适合内存,
如果您的JSON太大,无法 JSON_DECODE()
立即处理变得棘手。请参阅:
- php 中的大型JSON文件
- “>如何通过一个大JSON文件正确迭代
如何排序
请参阅:参考:在php 中对数组和数据进行排序和数据的所有基本方法。
如果您只想获得所有总销售额,则可以使用一个元。 此方法不按订单状态检查。
function get_total_sales_by_product_id( $atts ) {
return get_post_meta($atts['id'], 'total_sales', true);
}
add_shortcode('sales', 'get_total_sales_by_product_id');
要按订单状态列表获得总销售
function get_total_sales_by_product_id( $atts ){
$atts = shortcode_atts( array(
'id' => ''), $atts );
$product_id = $atts['id'];
if(empty($product_id)) return;
//Add remove order statuses
$order_status = array( 'wc-completed', 'wc-processing' );
global $wpdb;
$order_ids = $wpdb->get_col("
SELECT order_items.order_id
FROM {$wpdb->prefix}woocommerce_order_items as order_items
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID
WHERE posts.post_type = 'shop_order'
AND posts.post_status IN ( '" . implode( "','", $order_status ) . "' )
AND order_items.order_item_type = 'line_item'
AND order_item_meta.meta_key = '_product_id'
AND order_item_meta.meta_value = '$product_id'
");
$unique_order_ids = array_unique($order_ids);
$total_sales = 0;
foreach ($unique_order_ids as $order_id) {
$order = wc_get_order($order_id);
foreach ($order->get_items() as $item_key => $item ) {
if ($item->get_product()->get_id() == $product_id) {
$total_sales = $total_sales + $item->get_quantity();
}
}
}
return $total_sales;
}
add_shortcode('sales', 'get_total_sales_by_product_id');
您添加了 Action 作为空白的表单标签中
<form action="" enctype="multipart/form-data" method="post" id="form">
添加适当的URL名称在表单标签中
<form action="{% url 'post_url_name' %}" enctype="multipart/form-data" method="post" id="form">
通过使用附加
http客户端的方法解决了我的问题:
$ad_account_id = env("AD_ACCOUNT_ID");
$access_token = env("ACCESS_TOKEN");
$image = $request->file('image');
$response = Http::attach('filename', file_get_contents($image), 'image.jpg')
->post('https://graph.facebook.com/v14.0/act_' . $ad_account_id . '/adimages',
[
'access_token' => $access_token
]
);
dd(json_decode($response->body()));
$calendar['Monday'] = [ 'Otto Monday', 'Anna Monday' ];
$calendar['Tuesday'] = [ 'Fritz Tuesday' ];
$calendar['Wednesday'] = [];
$calendar['Thursday'] = [ 'Christine Thursday', 'More Thursday', 'Third Thursday' ];
$calendar['Friday'] = [];
$calendar['Saturday'] = [ 'Otto Saturday' ];
$calendar['Sunday'] = [ 'Otto Sunday' ];
$countOfRows = max(array_map(fn($item) => count($item), $calendar));
for ($index = 0; $index < $countOfRows; $index++) {
foreach ($calendar as $day => $items) {
$rows[$index][$day] = ( array_key_exists($index, $items) ) ? $items[$index] : '';
}
}
print_r($rows);
输出:
Array
(
[0] => Array
(
[Monday] => Otto Monday
[Tuesday] => Fritz Tuesday
[Wednesday] =>
[Thursday] => Christine Thursday
[Friday] =>
[Saturday] => Otto Saturday
[Sunday] => Otto Sunday
)
[1] => Array
(
[Monday] => Anna Monday
[Tuesday] =>
[Wednesday] =>
[Thursday] => More Thursday
[Friday] =>
[Saturday] =>
[Sunday] =>
)
[2] => Array
(
[Monday] =>
[Tuesday] =>
[Wednesday] =>
[Thursday] => Third Thursday
[Friday] =>
[Saturday] =>
[Sunday] =>
)
)
然后可以像这样生成HTML:
$thead = '<thead><tr>';
foreach(array_keys($calendar) as $day) {
$thead .= "<th>$day</th>";
}
$thead .= '</tr></thead>';
$tbody = '<tbody>';
foreach($rows as $row) {
$tbody .= "<tr>";
foreach($row as $value) {
$tbody .= "<td>$value</td>";
}
$tbody .= "</tr>";
}
$table = "<table>$thead$tbody</table>";
echo $table;
您在代码中调用两个函数:
upper_limit = int(input('Give me an upper limit:'))
guess(upper_limit)
这
computer_guess(100)
会导致两个功能运行。如果您想运行其中一个,只需编写 If
,然后询问必须运行哪一个:
print("computer or user? 1.computer 2. user")
if int(input()) == 1:
computer_guess(100)
else:
upper_limit = int(input('Give me an upper limit:'))
guess(upper_limit)
完成代码:
import random
def guess(x):
random_number = random.randint(1, x)
guess = 0
while guess != random_number:
guess = int(input(f'Guess a number between 1 and {x}:'))
if guess < random_number:
print('Sorry, guess again. Too low.')
elif guess > random_number:
print('Sorry, guess again. Too high.')
print(f'You guessed it bro, it was {random_number}')
def computer_guess(x):
low = 1
high = x
feedback = ''
while feedback != 'c':
if low != high:
guess = random.randint(low, high)
else:
guess = low # could also be high b/c low = high
feedback = input(f'Is {guess} too high (H), too low (L), or correct (C)?').lower()
if feedback == 'h':
high = guess - 1
elif feedback == 'l':
low = guess + 1
print(f'The computer guessed your number, {guess}, correctly')
print("computer or user? 1.computer 2. user")
if int(input()) == 1:
computer_guess(100)
else:
upper_limit = int(input('Give me an upper limit:'))
guess(upper_limit)
我会努力以下:
import re
import pandas
txt="""
[tab]e|------------------------------------------------------------------------|\r
\nB|----------3------5-------3----------------------------------------------|\r
\nG|---2-4---------------4----------4-2-0-----------------------------------|\r
\nD|---------------------------------------0---------------0-0--------------|\r
\nA|-----------------------------------------------------2------------------|\r
\nE|------------------------------------------------------------------------"""
pattern=r"(?<=e\|)[^|]*(?=\|%s)"%"\r"
matches=re.findall(pattern,txt)
dataframe=pandas.DataFrame([matches])
您的主页课很好。 Homecontroller类需要一些更改。
我已经纠正了,并且按预期工作正常。代码在下面给出。
class HomeController extends GetxController {
var selectedtIndex = 0.obs;
var appBartitle = "".obs;
@override
void onInit() {
super.onInit();
}
onTapNavigationBar(int index) {
selectedtIndex.value = index;
switch (index) {
case 0:
appBartitle.value = '1t';
break;
case 1:
appBartitle.value = '2t';
break;
case 2:
appBartitle.value = '3t';
break;
case 3:
appBartitle.value = '4t';
break;
}
}
void onTabChanged(int index) {
selectedtIndex.value = index;
}
}
VSCODE不是C ++编译器。它(主要是)文本编辑器和一些开发工具。它只是运行一些C ++编译器,以便实际编译和构建C ++代码。
您的实际C ++编译器是可以在哪里找到各种标头文件的最终权限。
无论出于何种原因,您的VSCODE配置都不知道Boost的标头文件已安装在哪里,所以这就是它告诉您的。您的编译器知道,但这是您的编译器,而不是VSCODE。
因此,不,VSCODE确实无法打开或找到这些标头文件。您的问题是:
我想知道为什么它这样做
因为它根本不知道。它不是您的C ++编译器,也不自动知道所有标头文件的安装位置。
以及如何修复
该问题...取决于您非常非常具体的计算机,操作系统(VSCODE可用于多个操作系统),无论您实际使用的C ++编译器与VSCODE使用哪个,以及如何 恰好< /strong> 您正在使用VSCODE(例如,我使用VSCODE来编辑甚至在同一台计算机上但通过SSH访问的文件)。这些因素中的每个因素都会影响一切的工作方式。
如果您知道Boost的标头文件的安装位置,这可能只是通过VSCODE的配置设置进行挖掘的问题,必须在某个地方进行设置,以告诉BOOST哪些目录包含要搜索的标头文件。如果您不知道安装了Boost的标头文件的位置,那么您的第一步将是在完成其他操作之前弄清楚该部分。
当数组中没有值时,您会遇到错误。因此,当您使用数组时,请先先检查它。
if (!empty($screens['kc-css']))
Hashmap不保证地图的顺序;特别是,它不能保证随着时间的流逝,订单将保持恒定。
改用LinkedHashMap,这看起来像:
Map sortedMap = new LinkedHashMap();
originalHashMap.entrySet().stream()
.sorted(Comparator.comparingInt(e -> e.getValue().size()))
.forEachOrdered(e -> sortedMap.put(e.getKey(), e.getValue()));
现在,预期排序的映射为SortedMap
如果将更改为
&amp;:Hover
嵌套的选择器将按预期进行编译。在您的原始代码中,:Hover
选择器嵌套在.nav-link中,但是由于嵌套时未直接引用父链选择器,因此它将其编译为两个独立的选择器,例如,EG .nav -link:悬停
。
使用 sass ampersand
&amp;
我们可以执行“可以执行”链接的“筑巢。 &amp;
在嵌套时始终引用父选择器。您可以将其视为指向父选择器的指针,其中&amp;
在您的示例中指的是 .nav-link
。因此,当我们这样做时:
.nav-link {
&:hover {
color: #f06;
}
}
它将其编译到 .nav-link:Hover {}
作为&amp;
使嵌套:Hover定义直接参考父母选择器 .nav-link
。以下是更新的代码:
.nav-link {
color: $color_light;
font-weight: 600;
font-size: 1.5em;
&:hover {
color: $color_vLight;
}
}
重要的!
#ID是独一无二的!
页面上的#id不超过相同的#id之一,因为它是:
- 无效的html
- 语义上的粗略
- 行为变得不可预测的
- JavaScript,如果不是立即,但最终破坏了
- 恐怖分子的胜利
,就像OP中的一吨一样:
<button type="submit" id="myButton">+</button> <!--
考虑以下代码:
请注意,我们如何使用单个字符串存储输入
String string = in.nextline();
,我们不需要字符串数组。一旦有字符串,我们就可以一次将一个字符传输到字符数组中。如果要处理多个字符串以存储在字符串数组
string [] string = new String [range];
中,那么我们可以使用嵌套循环:Consider the following code:
Note how we use a single string to store the input
String string = in.nextLine();
, we don't need a string array. Once we have the string we can transfer the characters one at a time into the character array.If you want to process multiple strings to store in a string array
String[] string = new String[range];
then we can use a nested loop:将输入在字符串阵列上传输到char数组