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

Unique array values in foreach

All,
I have a snippet of code below. In my foreach, I would like to process only
1 item per hdd value, in the case below, the echo $tib['hdd'] . "\n"; would
only display 1 and 2, not 1,1,1,1,2,2,2,2. It doesn't matter which one
shows, because I only want the unique value for hdd.

$tibs = array(
"tib1" => array("drive" => "C", "progress" => "on", "hdd" => "1",
"partition" => "1", "compression" => "3", "backup" => "K:\\"),
"tib2" => array("drive" => "D", "progress" => "on", "hdd" => "1",
"partition" => "2", "compression" => "3", "backup" => "K:\\"),
"tib3" => array("drive" => "E", "progress" => "on", "hdd" => "1",
"partition" => "3", "compression" => "3", "backup" => "K:\\"),
"tib4" => array("drive" => "F", "progress" => "on", "hdd" => "1",
"partition" => "4", "compression" => "3", "backup" => "K:\\"),
"tib5" => array("drive" => "G", "progress" => "on", "hdd" => "2",
"partition" => "1", "compression" => "3", "backup" => "L:\\"),
"tib6" => array("drive" => "H", "progress" => "on", "hdd" => "2",
"partition" => "2", "compression" => "3", "backup" => "L:\\"),
"tib7" => array("drive" => "I", "progress" => "on", "hdd" => "2",
"partition" => "3", "compression" => "3", "backup" => "L:\\"),
"tib8" => array("drive" => "J", "progress" => "on", "hdd" => "2",
"partition" => "4", "compression" => "3", "backup" => "L:\\"),
);

foreach($tibs as $tib) {
echo $tib['hdd'] . "\n";
}

Thanks for any help.
Jul 17 '05 #1
2 4589
m|sf|t wrote:
foreach($tibs as $tib) {
echo $tib['hdd'] . "\n";
}

Thanks for any help.


$_tibs = array();
foreach($tibs as $tib)
{
if ( !in_array($tib['hdd'], $_tibs) )
{
echo $tib['hdd'] . "\n";
$_tibs[] = $tib['hdd'];
}
}
Jul 17 '05 #2
whoa - that was smokin fast - thanks. i had to change $_tibs to $tibs to get
it to work, but it's working great now.
Thanks again =)

"Frank Jones" <fr***@spam.com> wrote in message
news:42*********************@uq-127creek-reader-03.brisbane.pipenetworks.com.au...
m|sf|t wrote:
foreach($tibs as $tib) {
echo $tib['hdd'] . "\n";
}

Thanks for any help.


$_tibs = array();
foreach($tibs as $tib)
{
if ( !in_array($tib['hdd'], $_tibs) )
{
echo $tib['hdd'] . "\n";
$_tibs[] = $tib['hdd'];
}
}

Jul 17 '05 #3

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

Similar topics

3
by: Bart Nessux | last post by:
The below code works well, except for the database insert. I want each element of the array to be inserted into the database, but only the last element of the array is inserted... all the elements...
2
by: HairlipDog58 | last post by:
I have a component that implements a property called obj of type object. The intent is that a user can pass in any value or array of values and I will be able to retrieve the values. If the...
1
by: Joep | last post by:
Hi, In VB.net I have an array which contains different values. For example: array(0) = 2 array(1) = 2 array(2) = 2 array(3) = 3 array(4) = 3 array(5) = 6 array(6) = 6
8
by: nescio | last post by:
hello, i have an array and i don't know the content of it, but i want only unique values. in php there is a function to do this, but how must i do this in javascript? i have tried a lot and...
22
by: guitarromantic | last post by:
Hey everyone, I run a site with staff-submitted reviews, and most of them are written by one author. However, we also do "multiple" reviews. Up until now I just had a userid for a 'Multiple'...
1
by: jerryyang_la1 | last post by:
I'm reading in a CSV and displaying using the code below: $users = file("text.txt"); echo "<table border='1' width='75%' align='center'>"; echo "<tr>"; echo "<td width='33%'...
9
by: Nathan Sokalski | last post by:
I am trying to use the System.Array.ForEach method in VB.NET. The action that I want to perform on each of the Array values is: Private Function AddQuotes(ByVal value As String) As String Return...
3
by: sberry | last post by:
I have three arrays... for instance $a = array('big', 'small', 'medium'); $b = array('old', 'new'); $c = array('blue', 'green'); I want to take those and end up with all of the combinations...
5
by: Ivan S | last post by:
I'm using next snippet: $somearray = array(...); foreach($somearray as $item1) { foreach($item1 as $item2) { // ... do something ... } }
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:
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...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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 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.