blinks Posted February 5, 2010 Share Posted February 5, 2010 I've the following line - $rsd_pids=$parsed_xml['PIDs']['pid']; which reads the content of the <pid> tag of an XML file. Sometimes there may be one <pid> tag, and sometimes more. My code works fine - creates an array - if there is more than one PID tag. $rsd_pids becomes a string if there is just one <pid>. How do I force it to read a single value as an array, not a string? TIA Link to comment https://forums.phpfreaks.com/topic/191014-may-be-an-array-or-may-not/ Share on other sites More sharing options...
oni-kun Posted February 5, 2010 Share Posted February 5, 2010 $rsd_pids[] = $parsed_xml['PIDs']['pid']; $rsd_pids = (array)$parsed_xml['PIDs']['pid']; This will enforce it into an array rather string or not. Link to comment https://forums.phpfreaks.com/topic/191014-may-be-an-array-or-may-not/#findComment-1007232 Share on other sites More sharing options...
blinks Posted February 5, 2010 Author Share Posted February 5, 2010 Thanks heaps! This works beautifully! Link to comment https://forums.phpfreaks.com/topic/191014-may-be-an-array-or-may-not/#findComment-1007246 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.