Cosizzle Posted May 15, 2009 Share Posted May 15, 2009 Hey, So i've gotten myself a little confused. Im loading a list of files into an array which works fine. Array ( [0] => todays_news.html [1] => helloWorld.php [2] => theStyles.css [3] => sackboyAngry.jpg ) Next I want to take this array and get just the file name, then the extension. Doing so I have this script. if (sizeOf($this->_fileArr) <= 0) { echo 'There are no files loaded. Please load files using the getFile() function'; } else { for ($i=0; $i<sizeOf($this->_fileArr); $i++) { $fName = basename($this->_fileArr[$i]); $this->_splitXtens[] = explode(".", $fName); } } Which works and gives me Array ( [0] => Array ( [0] => todays_news [1] => html ) [1] => Array ( [0] => helloWorld [1] => php ) ... so far so good. Where im stuck is if I wanted to call a specific element. echo $this->_fileArr[0][0]; will return 't' Why is it only returning the first letter of the name, but not the whole name (todays_news)? Quote Link to comment https://forums.phpfreaks.com/topic/158305-solved-exploding-an-array-and-calling-parts-of-it/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 15, 2009 Share Posted May 15, 2009 Because $this->_fileArr is the original list of filenames.ext $this->_splitXtens[] is what is holding the exploded parts. Quote Link to comment https://forums.phpfreaks.com/topic/158305-solved-exploding-an-array-and-calling-parts-of-it/#findComment-834938 Share on other sites More sharing options...
Cosizzle Posted May 15, 2009 Author Share Posted May 15, 2009 ugh right. I had that in before, it doesnt return anything however. echo $this->_splitXtensArr[0][0]; or echo $this->_splitXtensArr[0][0][0]; Quote Link to comment https://forums.phpfreaks.com/topic/158305-solved-exploding-an-array-and-calling-parts-of-it/#findComment-834943 Share on other sites More sharing options...
cunoodle2 Posted May 15, 2009 Share Posted May 15, 2009 Why are you appending "Arr" to the end of this array? Just do this.. echo $this->_splitXtens[0][0]; Quote Link to comment https://forums.phpfreaks.com/topic/158305-solved-exploding-an-array-and-calling-parts-of-it/#findComment-834945 Share on other sites More sharing options...
Maq Posted May 15, 2009 Share Posted May 15, 2009 so far so good. Where im stuck is if I wanted to call a specific element. echo $this->_fileArr[0][0]; will return 't' Why is it only returning the first letter of the name, but not the whole name (todays_news)? so far so good. Where im stuck is if I wanted to call a specific element. echo $this->_fileArr[0][0]; will return 't' Why is it only returning the first letter of the name, but not the whole name (todays_news)? That would imply that you are already in the correct array OR you have the wrong array. For example, when you do: $s = "blah"; echo $s[0]; This will echo 'b'. You must looking at the wrong array. I did a sample test with your data and it works fine: $arr = array(array("todays_new", "html"), array("helloWorld", "php")); print_r($arr); echo $arr[0][0]; ?> OUTPUTS: Array ( [0] => Array ( [0] => todays_new [1] => html ) [1] => Array ( [0] => helloWorld [1] => php ) ) todays_new Quote Link to comment https://forums.phpfreaks.com/topic/158305-solved-exploding-an-array-and-calling-parts-of-it/#findComment-834946 Share on other sites More sharing options...
Cosizzle Posted May 15, 2009 Author Share Posted May 15, 2009 Heh... got it working... it was a mix up in variable names. I was putting it into an array called _splitXtens should have been put into _splitXtensArr ... <sigh> such a silly error. Thanks for the quick feedback. Quote Link to comment https://forums.phpfreaks.com/topic/158305-solved-exploding-an-array-and-calling-parts-of-it/#findComment-834951 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.