I cannot find how to write empty Python struct/dictionary in PHP. When I wrote "{}" in PHP, it gives me an error. What is the equivalent php programming structure to Python's dictionary?
In php there are associative arrays, which are similar to dicionaries. Try to have a look to the documentation: http://php.net/manual/en/language.types.array.php
In python, you declare an empty dictionary like that:
m_dictionary = {} #empty dictionary
m_dictionary["key"] = "value" #adding a couple key-value
print(m_dictionary)
The way to do the same thing in php is very similar to the python's way:
$m_assoc_array = array();//associative array
$m_assoc_array["key"] = "value";//adding a couple key-value
print_r($m_assoc_array);
In PHP Python's dict
and list
will be the same array()
:
$arr = array();
$arr['a'] = 1;
print_r($arr['a']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With