Hi,
This is probably a no-brainer, but I could do with some help here.
I have some code which looks like this
$event = array("Date"=>array(), "Time"=>array(), "Venue"=>array(),
"Event"=>array());
$line = array();
while (!feof($fp))
{
$datein = fgets($fp, 200);
$lineleft = $datein;
$newpos = 0;
$pos = 0;
for ($i = 0; $i < 3; ++$i)
{
$newpos += strpos($lineleft, "*");
array_push($line, substr($datein, $pos, $newpos));
$newpos++;
$lineleft = substr($datein, $newpos, strlen($datein) - $newpos);
$pos = $newpos;
}
$month = substr($line[0], 5, 2);
$day = substr($line[0], 8, 2);
$year = substr($line[0], 0, 4);
if ($year >= $today['year'])
{
if ($month >= $today['mon'])
{
if (($month == $today['mon']) && ($day <= $today['mday']))
continue;
$datet = $day ."-" .$month."-".$year;
array_push($event['Date'], $datet);
}
}
array_push($event['Time'], $line[1]);
array_push($event['Venue'], $line[2]);
array_push($event['Event'], $line[3]);
}
fclose ($fp);
I know the substr stuff works (I can test that and it's fine and dandy).
I know the $month et al works as well (I've cut and pasted it from a
website I run at work). However, I'm not at all sure that how I'm using
the empty arrays (especially the multi-dimension array) is correct.
Could someone give me some advice on this?
Thanks
TTFN
Paul
--
"Logic, my dear Zoe, is merely the ability to be wrong with authority" -
Dr Who 4 1856
Paul wrote:
[snip] for ($i = 0; $i < 3; ++$i) { $newpos += strpos($lineleft, "*"); array_push($line, substr($datein, $pos, $newpos)); $newpos++; $lineleft = substr($datein, $newpos, strlen($datein) - $newpos); $pos = $newpos; }
Small oops, your loop only runs three times, but later you expect $line to
contain 4 values. Unless you have some special plan with the code above,
you could get the same result by just using:
$line = split("\*", $datein);
[snip] if ($year >= $today['year']) { if ($month >= $today['mon']) { if (($month == $today['mon']) && ($day <= $today['mday'])) continue; $datet = $day ."-" .$month."-".$year; array_push($event['Date'], $datet); } } array_push($event['Time'], $line[1]); array_push($event['Venue'], $line[2]); array_push($event['Event'], $line[3]);
In some conditions $event['Date'] does *not* get an value, while the others
(Time, Venue, Event) do. For instance if $year < $today['year']. I assume
it is not what you intended.
[snip] I know the substr stuff works (I can test that and it's fine and dandy). I know the $month et al works as well (I've cut and pasted it from a website I run at work). However, I'm not at all sure that how I'm using the empty arrays (especially the multi-dimension array) is correct.
Use of array_push looks fine.
You could use syntax like $event['Event'][] = $line[3], but the result would
be the same.
/Bent
Bent Stigsen wrote: Paul wrote: I know the substr stuff works (I can test that and it's fine and dandy). I know the $month et al works as well (I've cut and pasted it from a website I run at work). However, I'm not at all sure that how I'm using the empty arrays (especially the multi-dimension array) is correct.
Use of array_push looks fine. You could use syntax like $event['Event'][] = $line[3], but the result would be the same.
Thanks :-)
My main problem though is how to get data out of the array.
For example
echo $event['Event'][$i] . "<br />";
doesn't give anything - even if I have explicity put something into the
array (for example
$event['Event'][0] = "wibble";
$event['Event'][1] = "wobble";
$event['Event'][2] = "fibble";
$event['Event'][3] = "fobble";
for ($i = 0; $i < 4; ++$i)
echo $event['Event'][$i] . " ... " . $i . "<br />";
displays nothing other than " ... 0-3")
Is this more likely to be me or the version of php I'm using?
TTFN
Paul
In message <zi*******************@fe3.news.blueyonder.co.uk >
"Paul F. Johnson" <pa**@all-the-johnsons.co.uk> wrote: Bent Stigsen wrote:
Paul wrote:
I know the substr stuff works (I can test that and it's fine and dandy). I know the $month et al works as well (I've cut and pasted it from a website I run at work). However, I'm not at all sure that how I'm using the empty arrays (especially the multi-dimension array) is correct.
Use of array_push looks fine. You could use syntax like $event['Event'][] = $line[3], but the result would be the same.
Thanks :-)
My main problem though is how to get data out of the array.
For example
echo $event['Event'][$i] . "<br />";
doesn't give anything - even if I have explicity put something into the array (for example
$event['Event'][0] = "wibble"; $event['Event'][1] = "wobble"; $event['Event'][2] = "fibble"; $event['Event'][3] = "fobble";
for ($i = 0; $i < 4; ++$i) echo $event['Event'][$i] . " ... " . $i . "<br />";
displays nothing other than " ... 0-3")
Is this more likely to be me or the version of php I'm using?
TTFN
Paul
Have you tried [Event(1)]
--
Kev Wells http://kevsoft.topcities.com http://kevsoft.co.uk/
ICQ 238580561
The older I get the faster I used to be.
Paul F. Johnson wrote:
[snip] My main problem though is how to get data out of the array.
For example
echo $event['Event'][$i] . "<br />";
doesn't give anything - even if I have explicity put something into the array (for example
$event['Event'][0] = "wibble"; $event['Event'][1] = "wobble"; $event['Event'][2] = "fibble"; $event['Event'][3] = "fobble";
for ($i = 0; $i < 4; ++$i) echo $event['Event'][$i] . " ... " . $i . "<br />";
displays nothing other than " ... 0-3")
Is this more likely to be me or the version of php I'm using?
I've tried your example verbatim and output is fine, so I reckon it is
not your code.
I have run the same code on php versions from different major releases
(3.0.17, 4.3.9 and 5.1.2) giving exact same result, so I think it is
safe to say that it is not an issue of php version.
Sorry, I can't really say what your problem is. Perhaps your
braille-display is broken.
/Bent This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alan Searle |
last post by:
I have been trying to get an array to sort on a particular column and
have been having problems with my main key ...
array_multisort($dirlist, SORT_DESC, SORT_STRING);
This function takes an...
|
by: Cant Think Today |
last post by:
I have multi-dimesional arrays that can be specifed by the user, e.g
1,2,3,4,5
1,2,3,4,5,6,7,8,9,10
1,2,3,4,5,6
I think a bit of code that will iterate over these arrays to print out
the...
|
by: Adam Hartshorne |
last post by:
The input to a function of a 3rd party library I want to use requires a
double**, which is a multi-dimension array of doubles.
I have looked on the net etc and seen several ways of supposedly...
|
by: masood.iqbal |
last post by:
All this time I was under the illusion that I understand the concept of
multi-dimensional arrays well ---- however the following code snippet
belies my understanding.
I had assumed all along...
|
by: truckaxle |
last post by:
I am trying to pass a slice from a larger 2-dimensional array to a
function that will work on a smaller region of the array space. The
code below is a distillation of what I am trying to...
|
by: SouthSpawn |
last post by:
If I have an array that is
string MyArray = new string
Then I do the following.
string = "A";
How can I "ReDimension" my multi dimension array?
In VB.Net they have the ReDim Keyword.
|
by: rmorvay |
last post by:
I have a requirement to search a multi-dimensional array for an item, then
delete the item and "reset" the array so that their are no gaps in the
resulting array. I have been trying to figure out...
|
by: nw |
last post by:
Hi,
We've been having a discussion at work and I'm wondering if anyone
here would care to offer an opinion or alternative solution. Aparently
in the C programming HPC community it is common to...
|
by: ben.r.wood |
last post by:
I am not entirely sure, but after scanning the web believe I need to
use multi-dimensional arrays for my problem - although I have not seen
any examples of what I am trying to achieve.
I have a...
|
by: lovecreatesbea... |
last post by:
Is it always legal to cast expressions of type of multi-dimension
array to type of pointer?
Including:
T to T* ,
T to T* ,
T to T* ,
and so on...
For example:
int *mtxrot1d(int *p,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
| |