Jump to content

Recommended Posts

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)?

 

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.