php ???合??

WBOY
WBOY원래의
2016-06-23 14:24:17939검색

1. 把一???:
[{"0":"1011","post_id":"1011","1":"4","post_parent":"4","2":"hkbc_program_name_image","meta_key":"hkbc_program_name_image","3":"50","meta_value":"50"},{"0":"1011","post_id":"1011","1":"4","post_parent":"4","2":"hkbc_program_name_special","meta_key":"hkbc_program_name_special","3":"462","meta_value":"462"},{"0":"1011","post_id":"1011","1":"4","post_parent":"4","2":"hkbc_program_ad","meta_key":"hkbc_program_ad","3":"581","meta_value":"581"},{"0":"1011","post_id":"1011","1":"4","post_parent":"4","2":"hkbc_program_ad_url","meta_key":"hkbc_program_ad_url","3":"http:\/\/music.baidu.com\/","meta_value":"http:\/\/music.baidu.com\/"},{"0":"1011","post_id":"1011","1":"4","post_parent":"4","2":"hkbc_program_sort","meta_key":"hkbc_program_sort","3":"1.1","meta_value":"1.1"},1.1"},{"0":"1009","post_id":"1009","1":"117","post_parent":"117","2":"hkbc_program_name_image","meta_key":"hkbc_program_name_image","3":"119","meta_value":"119"},{"0":"1009","post_id":"1009","1":"117","post_parent":"117","2":"hkbc_program_name_special","meta_key":"hkbc_program_name_special","3":"463","meta_value":"463"},{"0":"1009","post_id":"1009","1":"117","post_parent":"117","2":"hkbc_program_ad","meta_key":"hkbc_program_ad","3":"111","meta_value":"111"},{"0":"1009","post_id":"1009","1":"117","post_parent":"117","2":"hkbc_program_ad_url","meta_key":"hkbc_program_ad_url","3":"http:\/\/baike.baidu.com\/view\/1433405.htm","meta_value":"http:\/\/baike.baidu.com\/view\/1433405.htm"},{"0":"1009","post_id":"1009","1":"117","post_parent":"117","2":"hkbc_program_sort","meta_key":"hkbc_program_sort","3":"7","meta_value":"7"}]
?合?一??似:
[{"post_id":"1011","post_parent":"4","hkbc_program_name_image":"50","hkbc_program_name_special":"462","hkbc_program_ad":"581","hkbc_program_ad_url":"http:\/\/music.baidu.com\/","hkbc_program_sort":"1.1"},{"post_id":"1009","post_parent":"117","hkbc_program_name_image":"119","hkbc_program_name_special":"463","hkbc_program_ad":"111","hkbc_program_ad_url":"http:\/\/baike.baidu.com\/view\/1433405.htm","hkbc_program_sort":"7"}]


回复讨论(解决方案)

密密麻麻,,我都不想看 能来个简单点的例子么

[{"0":"1011","post_id":"1011","1":"4","post_parent":"4","2":"hkbc_program_name_image","meta_key":"hkbc_program_name_image","3":"50","meta_value":"50"},{"0":"1011","post_id":"1011","1":"4","post_parent":"4","2":"hkbc_program_name_special","meta_key":"hkbc_program_name_special","3":"462","meta_value":"462"}]
?合?:
[{"post_id":"1011","post_parent":"4","hkbc_program_name_image":"50","hkbc_program_name_special":"462"}]

post_id 并不只有1101,?有很多

按json读取,merge再去掉整数key?

??了,是1011.
??格式是上面的格式,??是有很多的.

按json读取,merge再去掉整数key?
?面有用源??作?目???的?

你这个数据从哪里来的,没发现生成了数字键和字符键两份了吗,如果数字键非必须的话,可以在生成的时候只生成关联数组。

按json读取,merge再去掉整数key?
你??思路是正?的,??已?解?,?了?上??.

				/* # array filter				*  $array_param: array()				*/				function myfilter($array_param){					$temp = array();					$new_array = array();					foreach($array_param as $key=>$value){						if(array_key_exists($value["post_id"],$temp)){							$temp[$value["post_id"]] = array_merge($temp[$value["post_id"]],array($value["meta_key"]=>$value["meta_value"]));						}else{							$temp[$value["post_id"]] = array("post_id"=>$value["post_id"], "post_parent"=>$value["post_parent"], $value["meta_key"]=>$value["meta_value"]);						}					}					$new_array = array_values($temp);					return $new_array ;				}

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
이전 기사:SQL语句求指导다음 기사:PHP的If语法问题!