---
title: "php array merge and convert to json"  
description: "php array merge and convert to json"  
author: "Manoj Bhatt"  
published: 2013-05-02  
updated: 2013-05-02  
canonical: https://www.mindstick.com/forum/792/php-array-merge-and-convert-to-json  
category: "php"  
tags: ["php"]  
reading_time: 1 minute  

---

# php array merge and convert to json

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances)!\
I have [two arrays](https://www.mindstick.com/forum/161074/how-to-compare-two-arrays-to-each-other-in-javascript) (below). Is it [possible to convert](https://answers.mindstick.com/qa/96585/is-it-possible-to-convert-a-presentation-into-a-video-if-yes-how) them into json [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp)?\
[Array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net) ( [0] => size [1] => [color](https://www.mindstick.com/articles/77/how-to-split-form-background-color-in-c-sharp) )Array ( [0] => L [1] => Black )[Output](https://www.mindstick.com/interview/34427/explain-the-output-in-angular) [structure](https://www.mindstick.com/articles/23258/choose-your-business-structure-wisely) should be:\
[ {"name":"size","value":"L"}, {"name":"color","value":"Black"}]\
Thanks!

## Replies

### Reply by AVADHESH PATEL

Hi Manoj!\
\
Yes! It is possible to [convert](https://www.mindstick.com/forum/2093/configurationmanager-appsettings-convert-n-to-n-why) them into json string. You can try as below\
\
$array1 = array('size', 'color');\
$array2 = array('L', 'Black');\
\
$jsonArray = array();\
foreach (array_combine( $array1, $array2 ) as $name => $value) {\
$jsonArray[] = array('name' => $name, 'value' => $value);\
}\
\
echo $json = json_encode($jsonArray);\
This gives you\
\
[{"name":"size","value":"L"},{"name":"color","value":"Black"}]\
\
I hope it resolve your problem!


---

Original Source: https://www.mindstick.com/forum/792/php-array-merge-and-convert-to-json

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
