473,851 Members | 2,200 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=arr ay();

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<=hi ghest_allowed_v alue;$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 1504
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=arr ay();

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<=hi ghest_allowed_v alue;$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.co m
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
2762
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 icons are added to two ImageList objects which are bound to a ListView control, and everything looks great. I am saving the icons to a SQL Server table by using Icon.Save to a stream and assigning the byte array to the field, then loading them...
4
5500
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 this slows the program right down. Is there any way I can take a copy of the table in memory and access it there. Perhaps a cursor or something? Can someone help with a code sample. Here's my code to do the lookup.
104
17035
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 that array Could you show me a little example how to do this? Thanks.
2
2520
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 the array is an object itself but what is this syntax of the consecutive double quotes inside the brackets ?
0
5580
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 ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
5
2566
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 use to run a UM program, I kept on getting error messages. I have used someone else's implementation and it runs fine. I have compared my code with other's and I still can't figure it out what's wrong with mine. So please help me out, after 3...
3
2021
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 loop (easy) waiting for the mouse to be clicked (I dont need help with this) and depending on user input a variable might define what function I want (be it line, circle....(again these are my issues)
1
3664
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 image. my problem is i have captions to go with it and when i try to load the captions nothing happens or can be seen to be happening. i dont know where i am going wrong as i have no output or compiled errors var locVar = new Array();...
0
9898
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11020
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10670
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10735
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10356
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9506
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5736
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5934
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4549
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.