Hi Manoj! Yes! It is possible to convert 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!
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Yes! It is possible to convert 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!