If i have an array $string = array(1,2,6,2,9,6,7,3,1,2); How
can i get only unique values from it?
Array
(
[0] => 1
[1] => 2
[2] => 6
[4] => 9
[6] => 7
[7] => 3
)
Answer Posted / sreejesh1987
import java.io.*;
class Unique
{
public static void main(String args[])
{
int i,n;
int [] $string=new int[20];
DataInputStream ds=new DataInputStream(System.in);
try
{
System.out.println("Enter the number of elements:");
n=Integer.parseInt(ds.readLine());
System.out.println("Enter the numbers");
for(i=0;i<n;i++)
$string[i]=Integer.parseInt(ds.readLine());
for(i=0;i<n;i++)
{
int f=0;
for(int j=0;j<i;j++)
if($string[j]==$string[i])
f=1;
if(f==0)
System.out.print("$string["+i+"]:"+$string[i]+"\n");
}
}
catch(Exception e){}
System.exit(0);
}
}
Is This Answer Correct ? | 1 Yes | 1 No |
Post New Answer View All Answers
What is the best way to make wordpress plugin
can we pass variable in array to traverse it?
How can export database using php code?
What is used of serialize and unserialize in php?
Given a string=”me,I,myself”; .Using javascript only create an array out of this string and then send a POST request to the url “record.php” without reloading the page. The post key parameters should be n1,n2 and n3 respectively.
What is 301 redirects in php? When are we used 301 redirects in our projects?
Given a string=”me,I,myself”; .Using javascript only create an array out of this string and then send a POST request to the url “record.php” without reloading the page. The post key parameters should be n1,n2 and n3 respectively.
Which framework is best in php among Smarty, Cakephp, Joomla, Drupal, Zend or Something else...? If any then Why?
Is there any way to open notepad within php?
How can restrict user to type upto 8 characters in textbox in php?
How can call any javascript function without saying onclick, onchange, onblur etc events in php?
what is main difference between array_push and array_pop?
How can manage theme in php?
Which keyword is alias for count keyword in php?
How can i know that how many user are visited to my page in php?