Include Problem ?

Include Problem ?

am 26.10.2007 04:43:22 von Xav

Why does this not work ?

$fileDir = '../folder2/';
$content is an array of php files, file1.php file2.php file3.php
etc...

$c = count($content);
for( $x=0; $x<$c; $x++ ){
include( $fileDir.$content[$x] );
}

any ideas would be appreciated,
thanks.
Xav

Re: Include Problem ?

am 26.10.2007 07:31:53 von Xav

this seems to work,

....
for( $x=0; $x<$c; $x++ ){
include( $fileDir.'file'.($x+1).'.php' );

}
....

I don't understand why the other won't !
???

Xav

Re: Include Problem ?

am 26.10.2007 09:10:03 von dafox

Xav schrieb:
> Why does this not work ?

> $fileDir = '../folder2/';
> $content is an array of php files, file1.php file2.php file3.php
> etc...

> $c = count($content);
> for( $x=0; $x<$c; $x++ ){
> include( $fileDir.$content[$x] );
> }

This should work if $content really contains what you expect.

var_dump($content);

Re: Include Problem ?

am 26.10.2007 10:47:45 von Xav

I did the

...
thing...
it shows;

[0] => file1.php
[1] => file2.php
etc...

as expected!

I think I found a Bug!

this really doesn't work, I was thinking my logic was at fault,

could it be a php.ini setting problem ? I don't know of any settings
that govern logic.

thanks for response,
Xav

Re: Include Problem ?

am 26.10.2007 13:18:27 von luiheidsgoeroe

On Fri, 26 Oct 2007 13:04:58 +0200, Captain Paralytic =

wrote:
> On 26 Oct, 12:01, "Rik Wasmus" wrote:
>> On Fri, 26 Oct 2007 12:47:44 +0200, Captain Paralytic
>> > Surely {$content[$x]} won't work. PHP does only one substitution so=

>> > {$content[1]} will work but {$content[$x]} doesn't (at least in my
>> > experience).
>>
>> The code:
>> >> echo phpversion();
>> $foo =3D array(3 =3D> 'bar');
>> $x =3D 3;
>> echo "{$foo[$x]}";
>> ?>
>> Output:
>> 5.2.4bar
>>
>> The magic is in the braces.
>
> So would
> echo "$foo[$x]";
> not work then?

That's a whole other issue, and in this case it would work. See for a =

detailed explanation =

http://nl2.php.net/manual/en/language.types.string.php#langu age.types.st=
ring.parsing

Would we change it to this:
echo phpversion();
$foo =3D array(array(3 =3D> 'bar'));
$x =3D 3;
//works, outputs 'bar'
echo "{$foo[0][$x]}";
//doesn't work, outputs 'Array[3]'
echo "$foo[0][$x]"
?>

.... which is why it's a good thing to pick up the habit to use curly =

braces when using something other then a direct scalar in a string.
-- =

Rik Wasmus