我不知道如何在PHP中编写空的Python结构/字典。当我在PHP中写"{}"时,会出现错误。请问有哪种PHP编程结构与Python的字典相对应?
在php中,有关联数组,类似于字典。请查看文档:http://php.net/manual/en/language.types.array.php
在Python中,您可以这样声明一个空字典:
m_dictionary = {} #empty dictionary
m_dictionary["key"] = "value" #adding a couple key-value
print(m_dictionary)
在 PHP 中完成相同的任务的方式非常类似于 Python 的方式:
$m_assoc_array = array();//associative array
$m_assoc_array["key"] = "value";//adding a couple key-value
print_r($m_assoc_array);
dict
和list
都会被称为array()
。$arr = array();
$arr['a'] = 1;
print_r($arr['a']);
$empty = array();
就是空字典的等价形式。你具体遇到了什么问题?你有什么错误信息吗?请贴出更多的代码。 - Ivan Nevostruev$x = new stdClass();