Hey Guys, Is a php version of this javascript code? myVariable.getArray()[0].myVariable Code (markup): I want to be able to get the first variable in the array but without having to create a new variable to hold the array.
Um, well that depends..? Can you show us your PHP code / where you're getting the array from? Because a variable is either an array or it's not so you wouldn't have to create a new variable to hold it. Unless, of course, you're calling a function that returns an array (whether it's a function you created or a built-in one like explode()) in which case you can try to do callToFunction()[0] which would return the first value in the array. I'm not 100% if that'll work, I've honestly never tried to touch an array directly like that, so it might not work. But either way, in PHP, to access the first value of an array, just do $array_name[0]
Hi, Be more specific about what you need! In PHP if you an array say with the name $myVariable, then to access the first element in you can simply write $myVariable[0]. ~Maneet Puri
I'm trying to get data from a xml file. This is the xml file. <?xml version="1.0" encoding="utf-8"?> <settings> <sitename>AutoVideoScript 6.5</sitename> <sitetitle>Run your own Youtube clone web site</sitetitle> <sitedescription>This site is powered by AutoVideoScript 6.</sitedescription> <sitekeywords>youtube sharing script, media script</sitekeywords> <itemsperpage>20</itemsperpage> <contact_email>jack@jack.com</contact_email> <default_language>English</default_language> <default_template>inove</default_template> <enable_cache>0</enable_cache> <global_keywords>falling|funny</global_keywords> <exclude_keywords>sex|porn|teasing</exclude_keywords> <player_width>600</player_width> <player_height>450</player_height> <thumb_width>125</thumb_width> <thumb_height>90</thumb_height> <avatar_width>30</avatar_width> <avatar_height>30</avatar_height> <avs_affiliate>http://www.autovideoscript.com/</avs_affiliate> </settings> Code (markup): This is the javascript that works. var mysettings = xmldata.getElementsByTagName("settings")[0]; var sitename = mysettings.getElementsByTagName("sitename")[0].firstChild.data; var sitetitle = mysettings.getElementsByTagName("sitetitle")[0].firstChild.data; var sitedescription = mysettings getElementsByTagName("sitedescription")[0].firstChild.data; Code (markup): I want to do the same way in php but its not a correct syntax because of [0]. mysettings->getElementsByTagName("sitiename")[0]->firstChild->data Code (markup):
I figured it out. mysettings->getElementsByTagName("sitiename")->item[0]->firstChild->data Code (markup):