| | |
find index of values from array??
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2008
Posts: 293
Reputation:
Solved Threads: 11
hi,
out put
Array ( [amit] => 2 [hello] => 2 [world] => 1 )
i want to find the index of amit i.e
amit -> 0 and 2
hello -> 1 and 4
world -> 3
How to do this??
PHP Syntax (Toggle Plain Text)
$array = array("amit", "hello", "amit", "world", "hello"); print_r(array_count_values($array));
out put
Array ( [amit] => 2 [hello] => 2 [world] => 1 )
i want to find the index of amit i.e
amit -> 0 and 2
hello -> 1 and 4
world -> 3
How to do this??
Would this code do the trick?
php Syntax (Toggle Plain Text)
<? $array = array("amit", "hello", "amit", "world", "hello"); /* Sort into an array */ $i=0; foreach ($array AS $value){ $result[$value][]=$i; $i++; } /* Dump Result */ echo '<xmp>'; print_r($result); echo '</xmp><hr>'; /* Display Results */ foreach ($result AS $name=>$var) { echo $name.' '; foreach ($var AS $arrayposition) { echo $arrayposition.', '; } echo '<br>'; } ?>
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Don't do that, there's a built-in PHP function.
array_keys($array, "search_key") , that returns an array containing the indices for the searc_key GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
![]() |
Similar Threads
- How to find index of input array from sorted output? (C)
- Find the biggest element in that array (C++)
- Help on getting 2 lowest values in an array. (Java)
- find the upper limit of an array (C#)
- Help to find prime numbers without using an array (Java)
- find larget number in an array (C)
- integer values into array (Community Introductions)
- passing values from array to array (C)
- Using two vectors? (C++)
- Array Struct Sort Help!! Urgent! (C)
Other Threads in the PHP Forum
- Previous Thread: video tutorial
- Next Thread: Update Status MySpace and Linkedin via PHP API
| Thread Tools | Search this Thread |
ajax apache api array beginner beneath binary broadband broken button cakephp checkbox class cms code countingeverycharactersfromastring crack cron curl database date decode display dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail match md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf php problem protocol query radio random recursion regex remote script search server session sessions sms smtp soap source space sql strip_tags survey syntax system table tutorial undefined update upload url validator variable video virus votedown web window.onbeforeunload=closeme; xml youtube






