Jump to content

[SOLVED] Exploding an array and calling parts of it


Cosizzle

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.