I am designing a website that connects to AccuWeather's API. The language I am using for this project is PHP however, I only know how to code the async function I need in JS. For my website I want users to be able to search for a city and then get weather details for that city returned to them. As of now, I am only trying to query the city information and log it. That being said, how do I convert this function from JS to PHP? (This is my first question so please let me know how to improve on future questions)
This is the function in JS:
const getCity = async(city) => {
const base = 'http://dataservice.accuweather.com/locations/v1/cities/search';
const query = `?apikey=${key}&q=${city}`; //template string
const response = await fetch(base query);
return await response.json();
};
console.log(getCity('manchester')); //example city just to test if code works
CodePudding user response: