use*_*599 -2 php python arrays dictionary function
如何将PHP多维数组转换为Python字典格式的字符串?
var_dump($myarray);
array(2) { ["a1"]=> array(2) { ["29b"]=> string(0) "" ["29a"]=> string(0) "" } ["a2"]=> array(2) { ["29b"]=> string(0) "" ["29a"]=> string(0) "" } }
Run Code Online (Sandbox Code Playgroud)
如果您需要通过文本将PHP关联数组转换为Python字典,您可能需要使用JSON,因为两种语言都能理解它(尽管您需要为Python安装类似simpleJSON的东西).
http://www.php.net/manual/en/function.json-encode.php http://simplejson.readthedocs.org/en/latest/index.html
示例(显然这需要一些自动工作)......
<?php
$arr = array('test' => 1, 'ing' => 2, 'curveball' => array(1, 2, 3=>4) );
echo json_encode($arr);
?>
# elsewhere, in Python...
import simplejson
print simplejson.loads('{"test":1,"ing":2,"curveball":{"0":1,"1":2,"3":4}}')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5623 次 |
| 最近记录: |