这是我的代码。我想在数组或对象中添加新的键或项。我在foreach循环中添加了previewImage键到images数组。但它没有成功。当我打印图像阵列时,它显示正确。但是当我打印出foreach时,它不包含previewImage键。
if(!empty($scope) && $scope == "productList"){
$productList = $wpdb->get_results("SELECT * FROM products");
foreach($productList as $key => $value){
$images = (array) $value;
$images['previewImage'] = $fileUploadDir."/products/".$images['image'];
print_r($images['previewImage']);
//$value = (object) $images;
}
print_r($productList);
if($productList){
$response = array('status' => true, 'message' => 'Product success.', data => $productList);
} else addResponse(false, "product error", "null");
请给我解决方案......