Balan K Balan K - 6 months ago 17
PHP Question

combain two arrays in php array_combine not working?

First string:

_edit_last,_edit_lock,wpvp_fp_code,video_category


second string:

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


I need out put for:

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");

Answer

Use array merges recursive function to merge two arrays

For example

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

Array Combine Function:

 $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