473,395 Members | 2,443 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,395 software developers and data experts.

Help with php array loading/retrieval ???

Fellow PHP'ers;

I'm digging myself a hole on this one so I thought it has come to the
time when I must ask those who know.

I have what should be a simple question for loading, accessing and
retrieving values stored in a simple one-dimensional array.

I am simply trying to determine the occurrence of numbers as they
appear in a file. For example lets assume the lowest allowed value is
(00) and the highest allowed value is (35) and the numbers could occur
from zero to n times over the course of a period of time.

The problem I am having is referencing the array elements as strings
but it appears in reality its being references as a vector/index.

I am creating the array with:

$array_name=array();

then I am incrementing the count with:

$X=the number I've parsed from the file;
$array_name[$X]++;

then at the end I am using a for loop to print it out:

for($X=0;$X<=highest_allowed_value;$X++) {
print $X, $array_name[$X];
}

Of course, my field names are different and I think that the
references to the $X in the brackets are being interpreted as numeric
vectors but when I try to convert them to a string and use them it
also fails.

Can someone PLEASE set me straight on the proper technique to
accomplish this? As much as I've used PHP over the years I usually
have no issues with arrays except when I need strict numeric indexing.
Go figure.

Corrections? Suggestions? Advise? Anyone??

Thank you so much.

Signed: Frustrated PHP'er...
Feb 16 '06 #1
1 1485
bobmct wrote:
Fellow PHP'ers;

I'm digging myself a hole on this one so I thought it has come to the
time when I must ask those who know.

I have what should be a simple question for loading, accessing and
retrieving values stored in a simple one-dimensional array.

I am simply trying to determine the occurrence of numbers as they
appear in a file. For example lets assume the lowest allowed value is
(00) and the highest allowed value is (35) and the numbers could occur
from zero to n times over the course of a period of time.

The problem I am having is referencing the array elements as strings
but it appears in reality its being references as a vector/index.

I am creating the array with:

$array_name=array();

then I am incrementing the count with:

$X=the number I've parsed from the file;
$array_name[$X]++;

then at the end I am using a for loop to print it out:

for($X=0;$X<=highest_allowed_value;$X++) {
print $X, $array_name[$X];
}

Of course, my field names are different and I think that the
references to the $X in the brackets are being interpreted as numeric
vectors but when I try to convert them to a string and use them it
also fails.

Can someone PLEASE set me straight on the proper technique to
accomplish this? As much as I've used PHP over the years I usually
have no issues with arrays except when I need strict numeric indexing.
Go figure.

Corrections? Suggestions? Advise? Anyone??

Thank you so much.

Signed: Frustrated PHP'er...


Seems fine to me:

<?php
$read=array(
'00', '20', '14', '00', '29',
'14', '35', '20', '03', '06'
);
$new=array();
foreach($read as $x) $new[$x]++;
print_r($new);
?>

Result:
Array
(
[00] => 2
[20] => 2
[14] => 2
[29] => 1
[35] => 1
[03] => 1
[06] => 1
)

The key here is to be sure that the values in the $read array are
strings when pulled from the file. (Use var_dump() to check it out.)

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Feb 16 '06 #2

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

Similar topics

3
by: Tony Lugg | last post by:
I have an application with a document management form. When users add documents to the form, I call the API function SHGetFileInfo to get the associated large and small icons for the file. These...
4
by: andy.mcvicker | last post by:
Hi Gang I have a large VB program that at one point does a lookup to a small table (26 rows by 3 columns). With this table I have to do some counting and retrieval of data. I'm finding that...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
2
by: JJA | last post by:
I'm looking at some code I do not understand: var icons = new Array(); icons = new GIcon(); icons.image = "somefilename.png"; I read this as an array of icons is being built. An element of...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
5
by: weidongtom | last post by:
Hi, I tried to implement the Universal Machine as described in http://www.boundvariable.org/task.shtml, and I managed to get one implemented (After looking at what other's have done.) But when I...
3
by: googlinggoogler | last post by:
Hi This should all be pretty standard C stuff, but I'm going to use terms like mouse callback to communicate what Im tyring to do. Basically I have my program whirling around in an infinite...
1
anfetienne
by: anfetienne | last post by:
i have this code below that i made....it loads vars from txt file splits it then puts it into an array....once in an array it the brings the pics in from the array to create thumbnails and a larger...
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: 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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.