Page 1 of 1
problem with php algorithm
Posted: Thu Dec 29, 2011 5:57 am
by ugd
Code: Select all
foreach($values as $val =>$array) {
//echo $val . '<br/>';
//var_dump($array);
if(is_array($array))
{
var_dump($array);
}
else
{
echo $val;
}
}
I can't find a way to read variables in URL or in a vector or in text form so that it return just
the value which is reapeating,in case it is only one value to display it or in case there are only
different values to display all of them.Please help me!It's pretty urgent.
For example if I have 1,2,3,1,4 i would like it to display 1,and if I have 1,2,3,4 to display all of them.
Need help please

Re: problem with php algorithm
Posted: Thu Dec 29, 2011 3:14 pm
by Christopher
You might want to look at array_unique() or similar funcitons:
http://us.php.net/manual/en/function.array-unique.php
Re: problem with php algorithm
Posted: Thu Dec 29, 2011 5:42 pm
by twinedev
Is this something you are looking for?
Code: Select all
<pre><tt><?php
// SET UP RANDOM ARRAY OF DATA
$aryData = array();
for($t=0;$t<20;$t++) { $aryData[] = rand(1,20); }
// sort and output original array
sort($aryData); print_r($aryData);
// BEGIN: CODE TO FIND DUPLICATE ENTRIES
$aryCount = array_count_values($aryData);
foreach($aryCount as $value=>$count) {
if ($count==1) { unset($aryCount[$value]); }
}
$aryData = array_keys($aryCount);
unset($aryCount);
// END: CODE TO FIND DUPLICATE ENTRIES
// Sort and output array reduced to just duplicates
sort($aryData); print_r($aryData);
?></tt></pre>