473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

include with array

hi
i want to include rows in an array using include. but this always ends with
an error. any idea?

$files=array(
array(1,2,3),
array(2,3,4),
include "addon"
array(4,5,6)
}

addon:
<?php
array(3,4,5),
array(6,7,8),
?>

Jul 17 '05 #1
6 2451
It doesn't work this way (not that I aware off :)
include() can be used to include files.

$files=array(
array(1,2,3),
array(2,3,4),
array(4,5,6)
}

include "addon"

$newarray = array_merge( $files, $addon );

<?php

$addon=array(array(3,4,5),
array(6,7,8),
)
?>
"Alexander Gausa" <in***@gmx.de> wrote in message
news:d1*************@news.t-online.com...
hi
i want to include rows in an array using include. but this always ends
with
an error. any idea?

$files=array(
array(1,2,3),
array(2,3,4),
include "addon"
array(4,5,6)
}

addon:
<?php
array(3,4,5),
array(6,7,8),
?>

Jul 17 '05 #2
*** Alexander Gausa escribió/wrote (Sun, 13 Mar 2005 06:48:52 +0100):
i want to include rows in an array using include. but this always ends with
an error. any idea?

$files=array(
array(1,2,3),
array(2,3,4),
include "addon"
array(4,5,6)


Manual says:

"When a file is included, parsing drops out of PHP mode and into HTML mode
at the beginning of the target file, and resumes again at the end. For this
reason, any code inside the target file which should be executed as PHP
code must be enclosed within valid PHP start and end tags."

Testing shows that this working code:

<?php

$foo=array(1, 2, 3);
print_r($foo);

?>

cannot be rewritten as:

<?php

$foo=array(1, ?><?php 2, 3);

print_r($foo);

?>
Parse error: parse error, expecting `')'' in C:\tmp\borrame.php on line 3

I understand that you can't finish a PHP block in the middle of a sentence.
--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ Manda tus dudas al grupo, no a mi buzón
-+ Send your questions to the group, not to my mailbox
--
Jul 17 '05 #3
Alexander Gausa wrote:
i want to include rows in an array using include. but this always
ends with an error. any idea?

$files=array(
array(1,2,3),
array(2,3,4),
include "addon"
array(4,5,6)
}


addon:
<?php
$array = array(3,4,5);
$array2 = array(6,7,8);
?>

<?php
include "addon";

$files=array(
array(1,2,3),
array(2,3,4),
$array,
$array2,
array(4,5,6)
);
?>
JW

Jul 17 '05 #4
Alexander Gausa <in***@gmx.de> writes:
hi
i want to include rows in an array using include. but this always ends with
an error. any idea?

$files=array(
array(1,2,3),
array(2,3,4),
include "addon"
array(4,5,6)
}

addon:
<?php
array(3,4,5),
array(6,7,8),
?>


What you are trying to do here is employ include/require as if it were
a macro. My understanding is that it can't be used this way.

In fact your example can be made syntactically correct by putting a
comma after the include statement but all you'll get as return value
is either a 1 for success or false if the include failed.

But the code in the included file must be a complete statement, not a
fragment as you have shown above.

Try something like the M4 macro processor if you have an absolute need
for doing this.

HTH

--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/
Jul 17 '05 #5
why don't you try ... :)

$files[] = array(1,2,3);
$files[] = array(2,3,4);
include "addon"
$files[] = array(4,5,6);

addon:
<?php
$files[] = array(3,4,5);
$files[] = array(6,7,8);
?>

Jul 17 '05 #6

"Alexander Gausa" <in***@gmx.de> wrote in message
news:d1*************@news.t-online.com...
hi
i want to include rows in an array using include. but this always ends with an error. any idea?

$files=array(
array(1,2,3),
array(2,3,4),
include "addon"
array(4,5,6)
}

addon:
<?php
array(3,4,5),
array(6,7,8),
?>


That works in PHP 3 but not not PHP 4. See
http://www.php.net/manual/en/migration4.parser.php.
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
1
by: Sean Pinto | last post by:
Ok, you all are going to have to bear with me on this one as it is kinda complicated to explain. I am implementing a company management suite that requires Role-Based authentiations (ie. users are...
5
by: John Smith | last post by:
I'm having the folowing problem: I'm getting an Array from an external source, the data in the array depents on the get variables. These get variables should be decided by the browser, after...
60
by: Derrick Coetzee | last post by:
It seems like, in every C source file I've ever seen, there has been a very definite include order, as follows: - include system headers - include application headers - include the header...
5
by: Jonathan Ng | last post by:
Hi, I was wondering if there was a way to include the white spaces in a string. Currently, I am using: scanf("%s", &input); However, this doesn't include the 'space' character or any other...
2
by: Jofio | last post by:
I have 3 files, namely: dArray.h dArray.cp TestdArray.cpp Problem is when I compile the 'main' program - TestdArray.cpp - , it (the compiller) produces the following error: 'Unable to open...
2
by: 4Ankit | last post by:
hey guys i am having trouble changing my array code to include a 'for/ in' structure the code i am trying to change is below: <script type="text/javascript"> var contents = new Array(3)
17
by: Francine.Neary | last post by:
I have a program that uses a large lookup table, provided as a large array in the source: static int bigtbl={123, 456, /* etc. etc. */ 9999 }; Now this table is pretty big, and having it...
10
by: SoulIntruder | last post by:
Hello folks. I have a beginners question. I have such script: <?php $User = $_POST; $Password = $_POST; $Database = $_POST;
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.