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 Quote 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. Quote 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! Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.