IT_Architect
asked on
How can I store the VALUE of an object property in a variable?
PHP 5.3
How can I store the VALUE of an object property in a variable?
The output of this:
The output of this:
What I need is this:
Thanks!
How can I store the VALUE of an object property in a variable?
The output of this:
$fcst_ConditionIcon_array = $obj->data->parameters->{'conditions-icon'}->{'icon-link'};
echo "Forecast conditions-icon array" . PHP_EOL;
foreach ($fcst_ConditionIcon_array as $item) {
echo $item . PHP_EOL;
}
unset($item);
is this:Forecast conditions-icon array
http://forecast.weather.gov/newimages/medium/nshra60.png
http://forecast.weather.gov/DualImage.php?i=ra_sn&j=sn&ip=100&jp=80
http://forecast.weather.gov/newimages/medium/nsn50.png
http://forecast.weather.gov/newimages/medium/bkn.png
http://forecast.weather.gov/newimages/medium/nbkn.png
http://forecast.weather.gov/newimages/medium/sct.png
http://forecast.weather.gov/newimages/medium/nfew.png
http://forecast.weather.gov/newimages/medium/bkn.png
http://forecast.weather.gov/DualImage.php?i=nra_sn&j=nsn&ip=0&jp=0
http://forecast.weather.gov/DualImage.php?i=ra_sn&j=ra&ip=0&jp=0
http://forecast.weather.gov/newimages/medium/nra.png
http://forecast.weather.gov/newimages/medium/ra.png
http://forecast.weather.gov/newimages/medium/nbkn.png
http://forecast.weather.gov/newimages/medium/bkn.png
The output of this:
$ForecastTimes = array();
$i = 0;
foreach ($fcst_StartValidTime_array as $item) {
$ForecastTimes[$i] = $item;
++$i;
}
unset($item);
var_dump($ForecastTimes); echo PHP_EOL;
is this:
array(14) {
[0]=>
object(SimpleXMLElement)#6 (2) {
["@attributes"]=>
array(1) {
["period-name"]=>
string(7) "Tonight"
}
[0]=>
string(25) "2016-11-18T23:00:00-05:00"
}
[1]=>
object(SimpleXMLElement)#11 (2) {
["@attributes"]=>
array(1) {
["period-name"]=>
string(8) "Saturday"
}
[0]=>
string(25) "2016-11-19T06:00:00-05:00"
}
[2]=>
object(SimpleXMLElement)#12 (2) {
["@attributes"]=>
array(1) {
["period-name"]=>
string(14) "Saturday Night"
}
[0]=>
string(25) "2016-11-19T18:00:00-05:00"
}
[3]=>
object(SimpleXMLElement)#13 (2) {
["@attributes"]=>
array(1) {
["period-name"]=>
string(6) "Sunday"
}
[0]=>
string(25) "2016-11-20T06:00:00-05:00"
}
[4]=>
object(SimpleXMLElement)#14 (2) {
["@attributes"]=>
array(1) {
["period-name"]=>
string(12) "Sunday Night"
}
[0]=>
string(25) "2016-11-20T18:00:00-05:00"
}
[5]=>
object(SimpleXMLElement)#15 (2) {
["@attributes"]=>
array(1) {
["period-name"]=>
string(6) "Monday"
}
[0]=>
string(25) "2016-11-21T06:00:00-05:00"
}
[6]=>
object(SimpleXMLElement)#16 (2) {
["@attributes"]=>
array(1) {
["period-name"]=>
string(12) "Monday Night"
}
[0]=>
string(25) "2016-11-21T18:00:00-05:00"
}
[7]=>
object(SimpleXMLElement)#17 (2) {
["@attributes"]=>
array(1) {
["period-name"]=>
string(7) "Tuesday"
}
[0]=>
string(25) "2016-11-22T06:00:00-05:00"
}
[8]=>
object(SimpleXMLElement)#18 (2) {
["@attributes"]=>
array(1) {
["period-name"]=>
string(13) "Tuesday Night"
}
[0]=>
string(25) "2016-11-22T18:00:00-05:00"
}
[9]=>
object(SimpleXMLElement)#8 (2) {
["@attributes"]=>
array(1) {
["period-name"]=>
string(9) "Wednesday"
}
[0]=>
string(25) "2016-11-23T06:00:00-05:00"
}
[10]=>
object(SimpleXMLElement)#7 (2) {
["@attributes"]=>
array(1) {
["period-name"]=>
string(15) "Wednesday Night"
}
[0]=>
string(25) "2016-11-23T18:00:00-05:00"
}
[11]=>
object(SimpleXMLElement)#31 (2) {
["@attributes"]=>
array(1) {
["period-name"]=>
string(16) "Thanksgiving Day"
}
[0]=>
string(25) "2016-11-24T06:00:00-05:00"
}
[12]=>
object(SimpleXMLElement)#32 (2) {
["@attributes"]=>
array(1) {
["period-name"]=>
string(14) "Thursday Night"
}
[0]=>
string(25) "2016-11-24T18:00:00-05:00"
}
[13]=>
object(SimpleXMLElement)#30 (2) {
["@attributes"]=>
array(1) {
["period-name"]=>
string(6) "Friday"
}
[0]=>
string(25) "2016-11-25T06:00:00-05:00"
}
}
What I need is this:
array(14) {
[0]=>
string(56) "http://forecast.weather.gov/newimages/medium/nshra60.png"
[1]=>
string(67) "http://forecast.weather.gov/DualImage.php?i=ra_sn&j=sn&ip=100&jp=80"
[2]=>
string(54) "http://forecast.weather.gov/newimages/medium/nsn50.png"
etc., etc.
I end up with the object instead of the value. I need the value in order to assign it to a MySQL buffer.Thanks!
It looks like you ended up with an array of the links. What's wrong with that?
ASKER
It looks like you ended up with an array of the links. What's wrong with that?No I didn't. I ended up with objects in the array. What I need is an array of links like I show at the bottom.
If you change this (from the first code window):
The output that has objects is a looped var_dump of individual items in the output for forecast times. But what you need looks like a var_dump of the forecast condition icons without looping through and echoing each individual item.
$fcst_ConditionIcon_array = $obj->data->parameters->{'conditions-icon'}->{'icon-link'};
echo "Forecast conditions-icon array" . PHP_EOL;
foreach ($fcst_ConditionIcon_array as $item) {
echo $item . PHP_EOL;
}
unset($item);
to this:
$fcst_ConditionIcon_array = $obj->data->parameters->{'conditions-icon'}->{'icon-link'};
var_dump($fcst_ConditionIcon_array);
you should get what you need.The output that has objects is a looped var_dump of individual items in the output for forecast times. But what you need looks like a var_dump of the forecast condition icons without looping through and echoing each individual item.
Then how did you get the array of links at the bottom?
ASKER
@Kim Walker
That doesn't work.
This code:
That doesn't work.
This code:
$fcst_ConditionIcon_array = array();
$fcst_ConditionIcon_array = $obj->data->parameters->{'conditions-icon'}->{'icon-link'};
var_dump($fcst_ConditionIcon_array);
Produces this result:
object(SimpleXMLElement)#5 (1) {
[0]=>
string(56) "http://forecast.weather.gov/newimages/medium/nshra50.png"
}
ASKER
@Dave Baldwin
I wrote it by hand like this:
I wrote it by hand like this:
$fcst_ConditionIcon_array = array();
$fcst_ConditionIcon_array = array("http://forecast.weather.gov/newimages/medium/nshra60.png","http://forecast.weather.gov/DualImage.php?i=ra_sn&j=sn&ip=100&jp=80","http://forecast.weather.gov/newimages/medium/nsn50.png");
var_dump($fcst_ConditionIcon_array);
ASKER
This is the object that I am working with:
object(SimpleXMLElement)#3 (3) {
["@attributes"]=>
array(1) {
["version"]=>
string(3) "1.0"
}
["head"]=>
object(SimpleXMLElement)#4 (2) {
["product"]=>
object(SimpleXMLElement)#7 (3) {
["@attributes"]=>
array(3) {
["concise-name"]=>
string(9) "dwmlByDay"
["operational-mode"]=>
string(13) "developmental"
["srsName"]=>
string(8) "WGS 1984"
}
["creation-date"]=>
string(25) "2016-11-19T01:05:08-05:00"
["category"]=>
string(33) "current observations and forecast"
}
["source"]=>
object(SimpleXMLElement)#8 (3) {
["production-center"]=>
string(16) "Grand Rapids, MI"
["credit"]=>
string(27) "http://www.weather.gov/grr/"
["more-information"]=>
string(38) "http://www.nws.noaa.gov/forecasts/xml/"
}
}
["data"]=>
array(2) {
[0]=>
object(SimpleXMLElement)#5 (5) {
["@attributes"]=>
array(1) {
["type"]=>
string(8) "forecast"
}
["location"]=>
object(SimpleXMLElement)#8 (4) {
["location-key"]=>
string(6) "point1"
["point"]=>
object(SimpleXMLElement)#12 (1) {
["@attributes"]=>
array(2) {
["latitude"]=>
string(5) "43.02"
["longitude"]=>
string(6) "-85.54"
}
}
["area-description"]=>
string(24) "3 Miles ESE Northview MI"
["height"]=>
string(3) "659"
}
["moreWeatherInformation"]=>
string(61) "http://forecast.weather.gov/MapClick.php?lat=43.02&lon=-85.54"
["time-layout"]=>
array(3) {
[0]=>
object(SimpleXMLElement)#7 (3) {
["@attributes"]=>
array(2) {
["time-coordinate"]=>
string(5) "local"
["summarization"]=>
string(8) "12hourly"
}
["layout-key"]=>
string(12) "k-p12h-n14-1"
["start-valid-time"]=>
array(14) {
[0]=>
string(25) "2016-11-19T02:00:00-05:00"
[1]=>
string(25) "2016-11-19T06:00:00-05:00"
[2]=>
string(25) "2016-11-19T18:00:00-05:00"
[3]=>
string(25) "2016-11-20T06:00:00-05:00"
[4]=>
string(25) "2016-11-20T18:00:00-05:00"
[5]=>
string(25) "2016-11-21T06:00:00-05:00"
[6]=>
string(25) "2016-11-21T18:00:00-05:00"
[7]=>
string(25) "2016-11-22T06:00:00-05:00"
[8]=>
string(25) "2016-11-22T18:00:00-05:00"
[9]=>
string(25) "2016-11-23T06:00:00-05:00"
[10]=>
string(25) "2016-11-23T18:00:00-05:00"
[11]=>
string(25) "2016-11-24T06:00:00-05:00"
[12]=>
string(25) "2016-11-24T18:00:00-05:00"
[13]=>
string(25) "2016-11-25T06:00:00-05:00"
}
}
[1]=>
object(SimpleXMLElement)#9 (3) {
["@attributes"]=>
array(2) {
["time-coordinate"]=>
string(5) "local"
["summarization"]=>
string(8) "12hourly"
}
["layout-key"]=>
string(11) "k-p24h-n7-1"
["start-valid-time"]=>
array(7) {
[0]=>
string(25) "2016-11-19T02:00:00-05:00"
[1]=>
string(25) "2016-11-19T18:00:00-05:00"
[2]=>
string(25) "2016-11-20T18:00:00-05:00"
[3]=>
string(25) "2016-11-21T18:00:00-05:00"
[4]=>
string(25) "2016-11-22T18:00:00-05:00"
[5]=>
string(25) "2016-11-23T18:00:00-05:00"
[6]=>
string(25) "2016-11-24T18:00:00-05:00"
}
}
[2]=>
object(SimpleXMLElement)#10 (3) {
["@attributes"]=>
array(2) {
["time-coordinate"]=>
string(5) "local"
["summarization"]=>
string(8) "12hourly"
}
["layout-key"]=>
string(11) "k-p24h-n7-2"
["start-valid-time"]=>
array(7) {
[0]=>
string(25) "2016-11-19T06:00:00-05:00"
[1]=>
string(25) "2016-11-20T06:00:00-05:00"
[2]=>
string(25) "2016-11-21T06:00:00-05:00"
[3]=>
string(25) "2016-11-22T06:00:00-05:00"
[4]=>
string(25) "2016-11-23T06:00:00-05:00"
[5]=>
string(25) "2016-11-24T06:00:00-05:00"
[6]=>
string(25) "2016-11-25T06:00:00-05:00"
}
}
}
["parameters"]=>
object(SimpleXMLElement)#11 (7) {
["@attributes"]=>
array(1) {
["applicable-location"]=>
string(6) "point1"
}
["temperature"]=>
array(2) {
[0]=>
object(SimpleXMLElement)#12 (3) {
["@attributes"]=>
array(3) {
["type"]=>
string(7) "minimum"
["units"]=>
string(10) "Fahrenheit"
["time-layout"]=>
string(11) "k-p24h-n7-1"
}
["name"]=>
string(25) "Daily Minimum Temperature"
["value"]=>
array(7) {
[0]=>
string(2) "38"
[1]=>
string(2) "27"
[2]=>
string(2) "25"
[3]=>
string(2) "23"
[4]=>
string(2) "33"
[5]=>
string(2) "37"
[6]=>
string(2) "34"
}
}
[1]=>
object(SimpleXMLElement)#13 (3) {
["@attributes"]=>
array(3) {
["type"]=>
string(7) "maximum"
["units"]=>
string(10) "Fahrenheit"
["time-layout"]=>
string(11) "k-p24h-n7-2"
}
["name"]=>
string(25) "Daily Maximum Temperature"
["value"]=>
array(7) {
[0]=>
string(2) "39"
[1]=>
string(2) "34"
[2]=>
string(2) "39"
[3]=>
string(2) "41"
[4]=>
string(2) "45"
[5]=>
string(2) "46"
[6]=>
string(2) "47"
}
}
}
["probability-of-precipitation"]=>
object(SimpleXMLElement)#14 (3) {
["@attributes"]=>
array(3) {
["type"]=>
string(7) "12 hour"
["units"]=>
string(7) "percent"
["time-layout"]=>
string(12) "k-p12h-n14-1"
}
["name"]=>
string(38) "12 Hourly Probability of Precipitation"
["value"]=>
array(14) {
[0]=>
string(2) "30"
[1]=>
string(3) "100"
[2]=>
string(2) "70"
[3]=>
string(2) "20"
[4]=>
object(SimpleXMLElement)#19 (0) {
}
[5]=>
object(SimpleXMLElement)#20 (0) {
}
[6]=>
object(SimpleXMLElement)#21 (0) {
}
[7]=>
object(SimpleXMLElement)#22 (0) {
}
[8]=>
object(SimpleXMLElement)#23 (0) {
}
[9]=>
object(SimpleXMLElement)#24 (0) {
}
[10]=>
object(SimpleXMLElement)#25 (0) {
}
[11]=>
object(SimpleXMLElement)#26 (0) {
}
[12]=>
object(SimpleXMLElement)#27 (0) {
}
[13]=>
object(SimpleXMLElement)#28 (0) {
}
}
}
["weather"]=>
object(SimpleXMLElement)#15 (3) {
["@attributes"]=>
array(1) {
["time-layout"]=>
string(12) "k-p12h-n14-1"
}
["name"]=>
string(33) "Weather Type, Coverage, Intensity"
["weather-conditions"]=>
array(14) {
[0]=>
object(SimpleXMLElement)#28 (1) {
["@attributes"]=>
array(1) {
["weather-summary"]=>
string(25) "Chance Showers and Breezy"
}
}
[1]=>
object(SimpleXMLElement)#27 (1) {
["@attributes"]=>
array(1) {
["weather-summary"]=>
string(35) "Breezy. Rain/Snow then Snow Showers"
}
}
[2]=>
object(SimpleXMLElement)#26 (1) {
["@attributes"]=>
array(1) {
["weather-summary"]=>
string(32) "Snow Showers Likely and Blustery"
}
}
[3]=>
object(SimpleXMLElement)#25 (1) {
["@attributes"]=>
array(1) {
["weather-summary"]=>
string(45) "Slight Chance Snow Showers then Mostly Cloudy"
}
}
[4]=>
object(SimpleXMLElement)#24 (1) {
["@attributes"]=>
array(1) {
["weather-summary"]=>
string(13) "Mostly Cloudy"
}
}
[5]=>
object(SimpleXMLElement)#23 (1) {
["@attributes"]=>
array(1) {
["weather-summary"]=>
string(12) "Mostly Sunny"
}
}
[6]=>
object(SimpleXMLElement)#22 (1) {
["@attributes"]=>
array(1) {
["weather-summary"]=>
string(12) "Mostly Clear"
}
}
[7]=>
object(SimpleXMLElement)#21 (1) {
["@attributes"]=>
array(1) {
["weather-summary"]=>
string(12) "Partly Sunny"
}
}
[8]=>
object(SimpleXMLElement)#20 (1) {
["@attributes"]=>
array(1) {
["weather-summary"]=>
string(33) "Chance Rain/Snow then Snow Likely"
}
}
[9]=>
object(SimpleXMLElement)#19 (1) {
["@attributes"]=>
array(1) {
["weather-summary"]=>
string(33) "Rain/Snow Likely then Rain Likely"
}
}
[10]=>
object(SimpleXMLElement)#29 (1) {
["@attributes"]=>
array(1) {
["weather-summary"]=>
string(11) "Rain Likely"
}
}
[11]=>
object(SimpleXMLElement)#30 (1) {
["@attributes"]=>
array(1) {
["weather-summary"]=>
string(11) "Chance Rain"
}
}
[12]=>
object(SimpleXMLElement)#31 (1) {
["@attributes"]=>
array(1) {
["weather-summary"]=>
string(13) "Mostly Cloudy"
}
}
[13]=>
object(SimpleXMLElement)#32 (1) {
["@attributes"]=>
array(1) {
["weather-summary"]=>
string(13) "Mostly Cloudy"
}
}
}
}
["conditions-icon"]=>
object(SimpleXMLElement)#16 (3) {
["@attributes"]=>
array(2) {
["type"]=>
string(12) "forecast-NWS"
["time-layout"]=>
string(12) "k-p12h-n14-1"
}
["name"]=>
string(15) "Conditions Icon"
["icon-link"]=>
array(14) {
[0]=>
string(56) "http://forecast.weather.gov/newimages/medium/nshra30.png"
[1]=>
string(67) "http://forecast.weather.gov/DualImage.php?i=ra_sn&j=sn&ip=100&jp=90"
[2]=>
string(54) "http://forecast.weather.gov/newimages/medium/nsn70.png"
[3]=>
string(58) "http://forecast.weather.gov/DualImage.php?i=sn&j=bkn&ip=20"
[4]=>
string(53) "http://forecast.weather.gov/newimages/medium/nbkn.png"
[5]=>
string(52) "http://forecast.weather.gov/newimages/medium/sct.png"
[6]=>
string(53) "http://forecast.weather.gov/newimages/medium/nfew.png"
[7]=>
string(52) "http://forecast.weather.gov/newimages/medium/bkn.png"
[8]=>
string(66) "http://forecast.weather.gov/DualImage.php?i=nra_sn&j=nsn&ip=0&jp=0"
[9]=>
string(64) "http://forecast.weather.gov/DualImage.php?i=ra_sn&j=ra&ip=0&jp=0"
[10]=>
string(52) "http://forecast.weather.gov/newimages/medium/nra.png"
[11]=>
string(51) "http://forecast.weather.gov/newimages/medium/ra.png"
[12]=>
string(53) "http://forecast.weather.gov/newimages/medium/nbkn.png"
[13]=>
string(52) "http://forecast.weather.gov/newimages/medium/bkn.png"
}
}
["hazards"]=>
object(SimpleXMLElement)#17 (3) {
["@attributes"]=>
array(1) {
["time-layout"]=>
string(0) ""
}
["name"]=>
string(33) "Watches, Warnings, and Advisories"
["hazard-conditions"]=>
object(SimpleXMLElement)#32 (1) {
["hazard"]=>
object(SimpleXMLElement)#31 (2) {
["@attributes"]=>
array(1) {
["headline"]=>
string(25) "Hazardous Weather Outlook"
}
["hazardTextURL"]=>
string(166) "http://forecast.weather.gov/showsigwx.php?warnzone=MIZ057&warncounty=MIC081&firewxzone=MIZ057&local_place1=3+Miles+ESE+Northview+MI&product1=Hazardous+Weather+Outlook"
}
}
}
["wordedForecast"]=>
object(SimpleXMLElement)#18 (3) {
["@attributes"]=>
array(3) {
["time-layout"]=>
string(12) "k-p12h-n14-1"
["dataSource"]=>
string(9) "grrNetcdf"
["wordGenerator"]=>
string(12) "markMitchell"
}
["name"]=>
string(13) "Text Forecast"
["text"]=>
array(14) {
[0]=>
string(142) "A 30 percent chance of showers. Cloudy, with a low around 38. Breezy, with a west southwest wind 18 to 20 mph, with gusts as high as 32 mph. "
[1]=>
string(325) "A chance of rain showers before 8am, then rain and snow showers between 8am and 11am, then snow showers after 11am. Temperature falling to around 34 by 5pm. Breezy, with a west northwest wind 18 to 22 mph, with gusts as high as 37 mph. Chance of precipitation is 100%. New snow accumulation of less than one inch possible. "
[2]=>
string(241) "Snow showers likely, mainly before 8pm. Mostly cloudy, with a low around 27. Blustery, with a northwest wind 18 to 22 mph, with gusts as high as 39 mph. Chance of precipitation is 70%. New snow accumulation of less than one inch possible. "
[3]=>
string(145) "A 20 percent chance of snow showers before 8am. Mostly cloudy, with a high near 34. Northwest wind around 17 mph, with gusts as high as 29 mph. "
[4]=>
string(95) "Mostly cloudy, with a low around 25. Northwest wind 5 to 15 mph, with gusts as high as 24 mph. "
[5]=>
string(34) "Mostly sunny, with a high near 39."
[6]=>
string(35) "Mostly clear, with a low around 23."
[7]=>
string(34) "Partly sunny, with a high near 41."
[8]=>
string(149) "A chance of rain before 9pm, then a chance of rain and snow between 9pm and midnight, then snow likely after midnight. Cloudy, with a low around 33."
[9]=>
string(130) "Snow likely before 9am, then rain and snow likely between 9am and 10am, then rain likely after 10am. Cloudy, with a high near 45."
[10]=>
string(43) "Rain likely. Cloudy, with a low around 37."
[11]=>
string(54) "A chance of rain. Mostly cloudy, with a high near 46."
[12]=>
string(36) "Mostly cloudy, with a low around 34."
[13]=>
string(35) "Mostly cloudy, with a high near 47."
}
}
}
}
[1]=>
object(SimpleXMLElement)#6 (5) {
["@attributes"]=>
array(1) {
["type"]=>
string(20) "current observations"
}
["location"]=>
object(SimpleXMLElement)#11 (4) {
["location-key"]=>
string(6) "point1"
["point"]=>
object(SimpleXMLElement)#7 (1) {
["@attributes"]=>
array(2) {
["latitude"]=>
string(5) "42.88"
["longitude"]=>
string(6) "-85.52"
}
}
["area-description"]=>
string(54) "Grand Rapids, Gerald R. Ford International Airport, MI"
["height"]=>
string(3) "794"
}
["moreWeatherInformation"]=>
string(48) "http://www.nws.noaa.gov/data/obhistory/KGRR.html"
["time-layout"]=>
object(SimpleXMLElement)#10 (3) {
["@attributes"]=>
array(1) {
["time-coordinate"]=>
string(5) "local"
}
["layout-key"]=>
string(10) "k-p1h-n1-1"
["start-valid-time"]=>
string(25) "2016-11-19T01:53:00-05:00"
}
["parameters"]=>
object(SimpleXMLElement)#9 (8) {
["@attributes"]=>
array(1) {
["applicable-location"]=>
string(6) "point1"
}
["temperature"]=>
array(2) {
[0]=>
object(SimpleXMLElement)#7 (2) {
["@attributes"]=>
array(3) {
["type"]=>
string(8) "apparent"
["units"]=>
string(10) "Fahrenheit"
["time-layout"]=>
string(10) "k-p1h-n1-1"
}
["value"]=>
string(2) "42"
}
[1]=>
object(SimpleXMLElement)#8 (2) {
["@attributes"]=>
array(3) {
["type"]=>
string(9) "dew point"
["units"]=>
string(10) "Fahrenheit"
["time-layout"]=>
string(10) "k-p1h-n1-1"
}
["value"]=>
string(2) "31"
}
}
["humidity"]=>
object(SimpleXMLElement)#18 (2) {
["@attributes"]=>
array(2) {
["type"]=>
string(8) "relative"
["time-layout"]=>
string(10) "k-p1h-n1-1"
}
["value"]=>
string(2) "65"
}
["weather"]=>
object(SimpleXMLElement)#17 (3) {
["@attributes"]=>
array(1) {
["time-layout"]=>
string(10) "k-p1h-n1-1"
}
["name"]=>
string(33) "Weather Type, Coverage, Intensity"
["weather-conditions"]=>
array(2) {
[0]=>
object(SimpleXMLElement)#32 (1) {
["@attributes"]=>
array(1) {
["weather-summary"]=>
string(19) "Overcast and Breezy"
}
}
[1]=>
object(SimpleXMLElement)#31 (1) {
["value"]=>
object(SimpleXMLElement)#30 (1) {
["visibility"]=>
string(5) "10.00"
}
}
}
}
["conditions-icon"]=>
object(SimpleXMLElement)#16 (3) {
["@attributes"]=>
array(2) {
["type"]=>
string(12) "forecast-NWS"
["time-layout"]=>
string(10) "k-p1h-n1-1"
}
["name"]=>
string(15) "Conditions Icon"
["icon-link"]=>
string(58) "http://forecast.weather.gov/newimages/medium/nwind_ovc.png"
}
["direction"]=>
object(SimpleXMLElement)#15 (2) {
["@attributes"]=>
array(3) {
["type"]=>
string(4) "wind"
["units"]=>
string(12) "degrees true"
["time-layout"]=>
string(10) "k-p1h-n1-1"
}
["value"]=>
string(3) "240"
}
["wind-speed"]=>
array(2) {
[0]=>
object(SimpleXMLElement)#14 (2) {
["@attributes"]=>
array(3) {
["type"]=>
string(4) "gust"
["units"]=>
string(5) "knots"
["time-layout"]=>
string(10) "k-p1h-n1-1"
}
["value"]=>
string(2) "34"
}
[1]=>
object(SimpleXMLElement)#13 (2) {
["@attributes"]=>
array(3) {
["type"]=>
string(9) "sustained"
["units"]=>
string(5) "knots"
["time-layout"]=>
string(10) "k-p1h-n1-1"
}
["value"]=>
string(2) "22"
}
}
["pressure"]=>
object(SimpleXMLElement)#12 (2) {
["@attributes"]=>
array(3) {
["type"]=>
string(9) "barometer"
["units"]=>
string(17) "inches of mercury"
["time-layout"]=>
string(10) "k-p1h-n1-1"
}
["value"]=>
string(5) "29.80"
}
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@Ray Paseur
Earlier, when you said this is how to get at the object array:
You can almost always get the string by type-casting the object into a string, like this:WOW! You nailed it!
Earlier, when you said this is how to get at the object array:
$obj->data->parameters->{'conditions-icon'}->{'icon-link'};
What I'm not clear on, is the logic you used to do arrive at that.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I just got back from a customer.
In looking at that, what triggered you to enclose the last two in quotes and curly braces?
var_export($obj->data->parameters->{'conditions-icon'}->{'icon-link'});
In looking at that, what triggered you to enclose the last two in quotes and curly braces?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Got it! So that's why I had errors with my code with hypens, and had to switch to underscores to fix it. LOL! Thanks tons! I'm good for this topic. Thanks Tons!!!.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The code that loads the array from the object looks like this now:
$fcst_StartValidTime_array = $obj->data->{'time-layout'}[0]->{'start-valid-time'};
$ForecastTimes = array();
$i = 0;
foreach ($fcst_StartValidTime_array as $item) {
$ForecastTimes[$i] = (string)$item;
++$i;
}
unset($item);
The output, also using var_export, now looks like this:array (
0 => '2016-11-19T14:00:00-05:00',
1 => '2016-11-19T18:00:00-05:00',
2 => '2016-11-20T06:00:00-05:00',
3 => '2016-11-20T18:00:00-05:00',
4 => '2016-11-21T06:00:00-05:00',
5 => '2016-11-21T18:00:00-05:00',
6 => '2016-11-22T06:00:00-05:00',
7 => '2016-11-22T18:00:00-05:00',
8 => '2016-11-23T06:00:00-05:00',
9 => '2016-11-23T18:00:00-05:00',
10 => '2016-11-24T06:00:00-05:00',
11 => '2016-11-24T18:00:00-05:00',
12 => '2016-11-25T06:00:00-05:00',
)
Also, when posting code here at E-E, please use var_export() instead of var_dump().Got it! I changed the same output above to var_export(), and it looks like this now, and 200 lines shorter:
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'version' => '1.0',
),
'head' =>
SimpleXMLElement::__set_state(array(
'product' =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'concise-name' => 'dwmlByDay',
'operational-mode' => 'developmental',
'srsName' => 'WGS 1984',
),
'creation-date' => '2016-11-19T14:04:10-05:00',
'category' => 'current observations and forecast',
)),
'source' =>
SimpleXMLElement::__set_state(array(
'production-center' => 'Grand Rapids, MI',
'credit' => 'http://www.weather.gov/grr/',
'more-information' => 'http://www.nws.noaa.gov/forecasts/xml/',
)),
)),
'data' =>
array (
0 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'type' => 'forecast',
),
'location' =>
SimpleXMLElement::__set_state(array(
'location-key' => 'point1',
'point' =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'latitude' => '43.02',
'longitude' => '-85.54',
),
)),
'area-description' => '3 Miles ESE Northview MI',
'height' => '659',
)),
'moreWeatherInformation' => 'http://forecast.weather.gov/MapClick.php?lat=43.02&lon=-85.54',
'time-layout' =>
array (
0 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'time-coordinate' => 'local',
'summarization' => '12hourly',
),
'layout-key' => 'k-p12h-n13-1',
'start-valid-time' =>
array (
0 => '2016-11-19T14:00:00-05:00',
1 => '2016-11-19T18:00:00-05:00',
2 => '2016-11-20T06:00:00-05:00',
3 => '2016-11-20T18:00:00-05:00',
4 => '2016-11-21T06:00:00-05:00',
5 => '2016-11-21T18:00:00-05:00',
6 => '2016-11-22T06:00:00-05:00',
7 => '2016-11-22T18:00:00-05:00',
8 => '2016-11-23T06:00:00-05:00',
9 => '2016-11-23T18:00:00-05:00',
10 => '2016-11-24T06:00:00-05:00',
11 => '2016-11-24T18:00:00-05:00',
12 => '2016-11-25T06:00:00-05:00',
),
)),
1 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'time-coordinate' => 'local',
'summarization' => '12hourly',
),
'layout-key' => 'k-p24h-n7-1',
'start-valid-time' =>
array (
0 => '2016-11-19T14:00:00-05:00',
1 => '2016-11-20T06:00:00-05:00',
2 => '2016-11-21T06:00:00-05:00',
3 => '2016-11-22T06:00:00-05:00',
4 => '2016-11-23T06:00:00-05:00',
5 => '2016-11-24T06:00:00-05:00',
6 => '2016-11-25T06:00:00-05:00',
),
)),
2 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'time-coordinate' => 'local',
'summarization' => '12hourly',
),
'layout-key' => 'k-p24h-n6-2',
'start-valid-time' =>
array (
0 => '2016-11-19T18:00:00-05:00',
1 => '2016-11-20T18:00:00-05:00',
2 => '2016-11-21T18:00:00-05:00',
3 => '2016-11-22T18:00:00-05:00',
4 => '2016-11-23T18:00:00-05:00',
5 => '2016-11-24T18:00:00-05:00',
),
)),
),
'parameters' =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'applicable-location' => 'point1',
),
'temperature' =>
array (
0 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'type' => 'maximum',
'units' => 'Fahrenheit',
'time-layout' => 'k-p24h-n7-1',
),
'name' => 'Daily Maximum Temperature',
'value' =>
array (
0 => '34',
1 => '35',
2 => '38',
3 => '39',
4 => '43',
5 => '45',
6 => '45',
),
)),
1 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'type' => 'minimum',
'units' => 'Fahrenheit',
'time-layout' => 'k-p24h-n6-2',
),
'name' => 'Daily Minimum Temperature',
'value' =>
array (
0 => '28',
1 => '24',
2 => '23',
3 => '30',
4 => '36',
5 => '33',
),
)),
),
'probability-of-precipitation' =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'type' => '12 hour',
'units' => 'percent',
'time-layout' => 'k-p12h-n13-1',
),
'name' => '12 Hourly Probability of Precipitation',
'value' =>
array (
0 => '90',
1 => '40',
2 =>
SimpleXMLElement::__set_state(array(
)),
3 =>
SimpleXMLElement::__set_state(array(
)),
4 =>
SimpleXMLElement::__set_state(array(
)),
5 =>
SimpleXMLElement::__set_state(array(
)),
6 =>
SimpleXMLElement::__set_state(array(
)),
7 =>
SimpleXMLElement::__set_state(array(
)),
8 =>
SimpleXMLElement::__set_state(array(
)),
9 =>
SimpleXMLElement::__set_state(array(
)),
10 =>
SimpleXMLElement::__set_state(array(
)),
11 =>
SimpleXMLElement::__set_state(array(
)),
12 =>
SimpleXMLElement::__set_state(array(
)),
),
)),
'weather' =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'time-layout' => 'k-p12h-n13-1',
),
'name' => 'Weather Type, Coverage, Intensity',
'weather-conditions' =>
array (
0 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'weather-summary' => 'Snow Showers',
),
)),
1 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'weather-summary' => 'Chance Snow Showers',
),
)),
2 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'weather-summary' => 'Mostly Cloudy',
),
)),
3 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'weather-summary' => 'Mostly Cloudy',
),
)),
4 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'weather-summary' => 'Mostly Sunny',
),
)),
5 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'weather-summary' => 'Mostly Clear',
),
)),
6 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'weather-summary' => 'Partly Sunny',
),
)),
7 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'weather-summary' => 'Chance Wintry Mix then Snow Showers Likely',
),
)),
8 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'weather-summary' => 'Rain/Snow Likely then Showers Likely',
),
)),
9 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'weather-summary' => 'Showers Likely then Rain/Snow Likely',
),
)),
10 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'weather-summary' => 'Chance Rain/Snow then Slight Chance Showers',
),
)),
11 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'weather-summary' => 'Mostly Cloudy',
),
)),
12 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'weather-summary' => 'Chance Rain/Snow then Chance Showers',
),
)),
),
)),
'conditions-icon' =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'type' => 'forecast-NWS',
'time-layout' => 'k-p12h-n13-1',
),
'name' => 'Conditions Icon',
'icon-link' =>
array (
0 => 'http://forecast.weather.gov/newimages/medium/sn90.png',
1 => 'http://forecast.weather.gov/newimages/medium/nsn40.png',
2 => 'http://forecast.weather.gov/newimages/medium/bkn.png',
3 => 'http://forecast.weather.gov/newimages/medium/nbkn.png',
4 => 'http://forecast.weather.gov/newimages/medium/sct.png',
5 => 'http://forecast.weather.gov/newimages/medium/nfew.png',
6 => 'http://forecast.weather.gov/newimages/medium/bkn.png',
7 => 'http://forecast.weather.gov/DualImage.php?i=nfzra_sn&j=nsn&ip=0&jp=0',
8 => 'http://forecast.weather.gov/DualImage.php?i=ra_sn&j=shra&ip=0&jp=0',
9 => 'http://forecast.weather.gov/DualImage.php?i=nshra&j=nra_sn&ip=0&jp=0',
10 => 'http://forecast.weather.gov/DualImage.php?i=ra_sn&j=shra&ip=0&jp=0',
11 => 'http://forecast.weather.gov/newimages/medium/nbkn.png',
12 => 'http://forecast.weather.gov/DualImage.php?i=ra_sn&j=shra&ip=0&jp=0',
),
)),
'hazards' =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'time-layout' => '',
),
'name' => 'Watches, Warnings, and Advisories',
'hazard-conditions' =>
SimpleXMLElement::__set_state(array(
'hazard' =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'headline' => 'Hazardous Weather Outlook',
),
'hazardTextURL' => 'http://forecast.weather.gov/showsigwx.php?warnzone=MIZ057&warncounty=MIC081&firewxzone=MIZ057&local_place1=3+Miles+ESE+Northview+MI&product1=Hazardous+Weather+Outlook',
)),
)),
)),
'wordedForecast' =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'time-layout' => 'k-p12h-n13-1',
'dataSource' => 'grrNetcdf',
'wordGenerator' => 'markMitchell',
),
'name' => 'Text Forecast',
'text' =>
array (
0 => 'Snow showers. Steady temperature around 34. West northwest wind around 17 mph, with gusts as high as 38 mph. Chance of precipitation is 90%. Total daytime snow accumulation of less than one inch possible. ',
1 => 'A 40 percent chance of snow showers, mainly before midnight. Cloudy, with a low around 28. Northwest wind 14 to 16 mph, with gusts as high as 32 mph. ',
2 => 'Mostly cloudy, with a high near 35. Northwest wind 11 to 13 mph, with gusts as high as 26 mph. ',
3 => 'Mostly cloudy, with a low around 24. Northwest wind 5 to 8 mph. ',
4 => 'Mostly sunny, with a high near 38. Northwest wind 6 to 8 mph. ',
5 => 'Mostly clear, with a low around 23.',
6 => 'Partly sunny, with a high near 39.',
7 => 'A chance of rain or freezing rain before 8pm, then snow showers likely. Cloudy, with a low around 30.',
8 => 'Snow showers likely before 9am, then rain and snow showers likely between 9am and 10am, then rain showers likely after 10am. Cloudy, with a high near 43.',
9 => 'Rain showers likely before 5am, then a chance of rain and snow showers. Cloudy, with a low around 36.',
10 => 'A chance of rain and snow showers. Mostly cloudy, with a high near 45.',
11 => 'Mostly cloudy, with a low around 33.',
12 => 'A chance of rain and snow showers. Cloudy, with a high near 45.',
),
)),
)),
)),
1 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'type' => 'current observations',
),
'location' =>
SimpleXMLElement::__set_state(array(
'location-key' => 'point1',
'point' =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'latitude' => '42.88',
'longitude' => '-85.52',
),
)),
'area-description' => 'Grand Rapids, Gerald R. Ford International Airport, MI',
'height' => '794',
)),
'moreWeatherInformation' => 'http://www.nws.noaa.gov/data/obhistory/KGRR.html',
'time-layout' =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'time-coordinate' => 'local',
),
'layout-key' => 'k-p1h-n1-1',
'start-valid-time' => '2016-11-19T13:53:00-05:00',
)),
'parameters' =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'applicable-location' => 'point1',
),
'temperature' =>
array (
0 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'type' => 'apparent',
'units' => 'Fahrenheit',
'time-layout' => 'k-p1h-n1-1',
),
'value' => '32',
)),
1 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'type' => 'dew point',
'units' => 'Fahrenheit',
'time-layout' => 'k-p1h-n1-1',
),
'value' => '29',
)),
),
'humidity' =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'type' => 'relative',
'time-layout' => 'k-p1h-n1-1',
),
'value' => '88',
)),
'weather' =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'time-layout' => 'k-p1h-n1-1',
),
'name' => 'Weather Type, Coverage, Intensity',
'weather-conditions' =>
array (
0 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'weather-summary' => ' Snow Fog',
),
)),
1 =>
SimpleXMLElement::__set_state(array(
'value' =>
SimpleXMLElement::__set_state(array(
'visibility' => '0.50',
)),
)),
),
)),
'conditions-icon' =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'type' => 'forecast-NWS',
'time-layout' => 'k-p1h-n1-1',
),
'name' => 'Conditions Icon',
'icon-link' => 'http://forecast.weather.gov/newimages/medium/sn.png',
)),
'direction' =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'type' => 'wind',
'units' => 'degrees true',
'time-layout' => 'k-p1h-n1-1',
),
'value' => '300',
)),
'wind-speed' =>
array (
0 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'type' => 'gust',
'units' => 'knots',
'time-layout' => 'k-p1h-n1-1',
),
'value' => '20',
)),
1 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'type' => 'sustained',
'units' => 'knots',
'time-layout' => 'k-p1h-n1-1',
),
'value' => '16',
)),
),
'pressure' =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'type' => 'barometer',
'units' => 'inches of mercury',
'time-layout' => 'k-p1h-n1-1',
),
'value' => '29.96',
)),
)),
)),
),
))
ASKER
Fabulous help! He hit it out of the park!