View Full Version : php version of myVariable.getArray()[0].myVariable
SGBoise
Dec 23rd 2008, 8:50 pm
Hey Guys,
Is a php version of this javascript code?:confused:
myVariable.getArray()[0].myVariable
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.
zerxer
Dec 23rd 2008, 11:55 pm
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]
maneetpuri
Dec 24th 2008, 4:37 am
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
SGBoise
Dec 24th 2008, 8:13 am
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>
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;
I want to do the same way in php but its not a correct syntax because of [0].
mysettings->getElementsByTagName("sitiename")[0]->firstChild->data
SGBoise
Dec 24th 2008, 2:16 pm
I figured it out.
mysettings->getElementsByTagName("sitiename")->item[0]->firstChild->data
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.