The trick is keeping track of the array index values so you can update the original.
foreach ($JSON_array['Products'] as $productIndex => $product)
{
$JSON_array['Products'][$productIndex]['image'] = base64_encode($product['image']);
$JSON_array['Products'][$productIndex]['image_front'] = base64_encode($product['image_front']);
$JSON_array['Products'][$productIndex]['image_back'] = base64_encode($product['image_back']);
}
This updates the original array outside of the loop with base64_encode
values. Then you should be able to easily json_encode()
that array.
$output = json_encode($JSON_array);