<?php $arrAccesories = '[{"value":"Charger"},{"value":"Bag Only"},{"value":"Data Privacy Filter"},{"value":"Headset"}]'; $arrAccesories = json_decode($arrAccesories); $accessoriesID = [ "Charger" => "11043", "Mouse" => "11044", "Bag With Strap" => "11045", "Bag Only" => "11046", "Cable Lock" => "11047", "Data Privacy Filter" => "11048", "Numeric Lock" => "11049", "Headset" => "11050", "HDMI to VGA adapter" => "11051", "LAN Adapter" => "12223", "Others (Please include in the remarks box below.)" => "11052" ]; $default = $accessoriesID['Others (Please include in the remarks box below.)']; foreach ($arrAccesories as $row) { $row->id = $accessoriesId[$row->value] ?? $default; } echo json_encode($arrAccesories);
You have javascript disabled. You will not be able to edit any code.