时间:2021-07-01 10:21:17 帮助过:3人阅读
$data = array();$data['result'] = array();// 任意条$data['result'][] = array('userid' => '001', 'username': '李明');
$a = array( 'result' => array( array( 'userid' => '001', 'username' => '李明'), ),);array_walk_recursive($a, 'encode');echo urldecode(json_encode($a));$a = array( 'result' => array( array( 'userid' => '001', 'username' => '张飞'), array( 'userid' => '001', 'username' => '张飞'), ),);array_walk_recursive($a, 'encode');echo urldecode(json_encode($a));function encode(&$item, $key) { $item = urlencode($item);}{"result":[{"userid":"001","username":"李明"}]}
观看,有些不太懂,学习。
感谢xuzuning与dream1206!
请问xuzuning,
$a = array(
'result' => array(
array( 'userid' => '001', 'username' => '张飞'),
array( 'userid' => '001', 'username' => '张飞'),
),
);
以上数组中,"array( 'userid' => '001', 'username' => '张飞'),"能否是一个变量,可以动态的增加呢,比如:
$a = array(
'result' => array(
array( 'userid' => '001', 'username' => '张飞1'),
array( 'userid' => '001', 'username' => '张飞2'),
array( 'userid' => '001', 'username' => '张飞3'),
),
);
谢谢!