在php array_combine中组合两个数组不起作用?

时间:2016-06-04 06:51:54

标签: php arrays

第一个字符串:

$a = '_edit_last,_edit_lock,wpvp_fp_code,video_category';

第二个字符串:

$ b ='1,1464965316:1,{“src”:“http://localhost/wbg/wp-content/uploads/2016/05/PHP-Tutorial-1-Introduction-PHP-For-Beginners.mp4”,“splash”:“http://localhost/wbg/wp-content/uploads/2016/05/default_image.jpg”,“width”:“640”,“height”: “360”},免费200';

将String转换为组合数组。

我需要出去:

array("_edit_last"=>" 1", "_edit_lock"=>"1464965316:1", "wpvp_fp_code"=>"{"src":"http://localhost/wbg/wp-content/uploads/2016/05/PHP-Tutorial-1-Introduction-PHP-For-Beginners.mp4","splash":"http://localhost/wbg/wp-content/uploads/2016/05/default_image.jpg","width":"640","height":"360"}","video_category"=>"free 200");

1 个答案:

答案 0 :(得分:1)

使用数组合并递归函数来合并两个数组

例如

 $ar1 = array("color" => array("favorite" => "red"), 5);
 $ar2 = array(10, "color" => array("favorite" => "green", "blue"));
 $result = array_merge_recursive($ar1, $ar2);
 print_r($result);

阵列组合功能:

 $a = array('_edit_last', '_edit_lock', 'wpvp_fp_code', 'video_category');
 $b = array('1', '1464965316:1', '"{src":"http://localhost/wbg/wp-content/uploads/2016/05/PHP-Tutorial-1-Introduction-PHP-For-Beginners.mp4","splash":"http://localhost/wbg/wp-content/uploads/2016/05/default_image.jpg","width":"640","height":"360"}','free 200');
 $c = array_combine($a, $b);
 echo "<pre>";
 print_r($c);

WATCH DEMO

将sting转换为数组

$str = '_edit_last,_edit_lock,wpvp_fp_code,video_category';
print_r (explode(", ",$str));

DEMO

我在string2中使用了双空格而不是逗号(,)。因为逗号(,)不是一个独特的函数

DEMO - 3