I am trying to get data from this json file, but I need the data that matches the advanced custom field I setup.
$str = file_get_contents('http://gold.explorethatstore.com/wp-content/themes/divi-ETS-child-theme/run_results_bgasc.json');
// decode JSON
$json = json_decode($str, true);
// default value
$coinPrice = "Not Available";
$vendorName = get_field('bgasc_vendor_name');
// loop the json array
foreach($json['coin'] as $value){
// check the condition
if($value['coin_name'] == $vendorName){
$coinPrice = $value['url']; // get the price
break; // exit the loop
}
}
echo $coinPrice;
So here is the correct code that will handle both array cases (with or without "weight" array):
This code is tested and works