By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,289 Members | 1,391 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,289 IT Pros & Developers. It's quick & easy.

Unique array values in foreach

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.