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

Assoc Arrays

I have a script which retrives a list of files then reads the first
two lines of each one of these files.
Code:
function retrieve_headers($username)
{
if(!file_exists('c:/'.$username))
return false;
$directory = opendir("c:/$username//");
$ary=array();
while($file = readdir($directory))
{
if(!(is_dir($file) || ($file=='.') || ($file =='..')))
{
$fp = fopen("c:/$username/$file", "r");
$recip = fgets($fp);
$sender = fgets($fp);
array_push($ary,"$recip$sender");
fclose($fp);
}
}
return $ary;
}
The idea is I want an array with $recip as the key and $sender as the
value.
Unfortunently the above code outputs an array like this:
Code:
0 => foo bar
1 => foo bar
2 => foo bar
Any idea how I could go about this?
Jul 17 '05 #1
3 3574
"David" <bi****@hotmail.com> wrote in message
news:3e**************************@posting.google.c om...
... $fp = fopen("c:/$username/$file", "r");
$recip = fgets($fp);
$sender = fgets($fp);
array_push($ary,"$recip$sender");
fclose($fp);
....
The idea is I want an array with $recip as the key and $sender as the
value.

change:
array_push($ary,"$recip$sender");
to:
$ary[$recip] = $sender;
--

Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #2
> change:
array_push($ary,"$recip$sender");
to:
$ary[$recip] = $sender;


That works but it removes all duplicates which I do not want. Is there
a way to do this without removing duplicate values?
Jul 17 '05 #3
David <bi****@hotmail.com> wrote:
change:
array_push($ary,"$recip$sender");
to:
$ary[$recip] = $sender;


That works but it removes all duplicates which I do not want. Is there
a way to do this without removing duplicate values?


the key of an array element is unique. wouldn't it be easier to
fill two arrays? or fill the array with two-element arrays, if you
need everything inside one array.

steven.
Jul 17 '05 #4

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

Similar topics

19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
5
by: JezB | last post by:
What's the easiest way to concatenate arrays ? For example, I want a list of files that match one of 3 search patterns, so I need something like DirectoryInfo ld = new DirectoryInfo(searchDir);...
1
by: steletroll | last post by:
Hi, i'm getting crazy... I am in the process to migrate all my vbscripts to C#, but i can't retrieve some attributes of mailboxes with DirectoryService (particularly Assoc-NT-Account). So if...
5
by: steletroll | last post by:
Hi, i'm getting crazy... I try to translate my vbscripts to C# but i can't retrieve some attributes of an Exchange 5.5 mailbox (particularly Assoc-NT-Account). So, if someone had a piece of...
6
by: lwoods | last post by:
I want to be able to get the present year in one statement. I know that I can do it this way: $y = getdate(); echo 'year='.$y; But, I want to do something like: echo 'year='.getdate(); ...
1
by: Rob Griffiths | last post by:
Can anyone explain to me the difference between an element type and a component type? In the java literature, arrays are said to have component types, whereas collections from the Collections...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
19
Purple
by: Purple | last post by:
Hi All, What is the best way to create an XML stream from an assoc array in php. Regards Purple
5
by: KDawg44 | last post by:
Hi, Is there a way to get a multidimensional associative array with the entire result set? I would like to get a an array like this: resultsArray How can I accomplish this? Can I do...
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
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
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...
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...
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...
0
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,...

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.