473,382 Members | 1,409 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,382 software developers and data experts.

how do you access an array in an included/required field?

I have a large array that would be messy to include in the file "main.php"
itself and would prefer to include/require it. Say I have the following
line in "main.php":

require_once('/arr.php');

And the "arr.php" file looks something like this:

<?php
array(1)='***@Ok.com';
array(2)='***@Ok.com';
array(3)='***@Ok.com';
array(4)='***@Ok.com';
array(5)='***@Ok.com';
array(6)='***@Ok.com';
array(7)='***@Ok.com';
array(8)='***@Ok.com';
array(9)='***@Ok.com';
array(10)='****@Ok.com';
?>

Would I be able to reference the array AS IF I had declared the array in
"main.php"?

I am a programmer but new to PHP.

Many thanks.
Jul 17 '05 #1
3 2016
NotGiven wrote:
I have a large array that would be messy to include in the file "main.php"
itself and would prefer to include/require it. Say I have the following
line in "main.php":

require_once('/arr.php');

And the "arr.php" file looks something like this:

<?php
array(1)='***@Ok.com'; [snipped] ?>

Would I be able to reference the array AS IF I had declared the array in
"main.php"?

I am a programmer but new to PHP.


What hapenned when you tried it?

I guess your problem is with the require_once(). Are you sure you have
arr.php on the root dir?
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
Pedro Graca wrote:
NotGiven wrote:
<?php
array(1)='***@Ok.com';
I guess your problem is with the require_once(). Are you sure you have
arr.php on the root dir?


And that the syntax for the array is wrong:

1. you need the $ before the array name
2. the array elements are specified with []

so ...

<?php
$array[1] = 'o**@Ok.com';
?>
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #3
NotGiven wrote:
I have a large array that would be messy to include in the file "main.php"
itself and would prefer to include/require it. Say I have the following
line in "main.php":

require_once('/arr.php');

And the "arr.php" file looks something like this:

<?php
array(1)='***@Ok.com';
array(2)='***@Ok.com';
array(3)='***@Ok.com';
array(4)='***@Ok.com';
array(5)='***@Ok.com';
array(6)='***@Ok.com';
array(7)='***@Ok.com';
array(8)='***@Ok.com';
array(9)='***@Ok.com';
array(10)='****@Ok.com';
?>
This is incorrect syntax. Try:

<?php
$array = array(
1 => "ok*@Ok.com",
2 => "ok*@Ok.com",
3 => "ok*@Ok.com"
);
?>
Would I be able to reference the array AS IF I had declared the array in
"main.php"?


Yes. When you include/require the array, you can treat it as it is
declared in the file it's included in. Thus, this is a valid main.php:

<?php

require_once('arr.php');

echo $array[1];

?>

--
Tormod Fjeldskår
to****@fritidsproblemer.no
http://tormod.fritidsproblemer.no/
Jul 17 '05 #4

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

Similar topics

9
by: Brian | last post by:
Hello, I have a text file I'm attempting to parse. There are about 50 fixed width fields in each line / row. For example (shortened for brevity): W1234Somebody East 101110001111010101...
1
by: J Askey | last post by:
Is this object available in Access? If so, what do I need to set a reference to? My bigger picture is needing a way to take a .bmp out of a SQL database and put into both an CommandBarButton...
49
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The...
6
by: F-13 | last post by:
I'm working on a BOM in Access 200 from an example downloaded from from the web. The sample database contains three tables, Assemblies (the list of items needed to assemble any assembly),...
15
by: Claudio Grondi | last post by:
Let's consider a test source code given at the very end of this posting. The question is if Python allows somehow access to the bytes of the representation of a long integer or integer in...
4
by: Miro | last post by:
Im trying to store data as I would in some old language. Old Example //Create an array that holds 3 different variable types TempArray := { { "Hello", 1, False }, { "Goodbye", 123, True } } ...
4
by: alexandre.brisebois | last post by:
Hi, I am using access 2003, I would like to know if there is an option to reorganize the tables in a maner that is readable, as we can do in sql sever 2000 or 2005. I have been given a database...
36
by: Peter Olcott | last post by:
So far the only way that I found to do this was by making a single global instance of the container class and providing access to the contained class, through this single global instance. Are...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.