Jump to content

[SOLVED] need help with making function like array_unique()


FD_F

Recommended Posts

here is my code any advice what i`m doing wrong ?

 

$str = "‫‪the brown fox jumped over the white fox‬‬";
$NewStr = split(" ", $str);


$flag = 0;

foreach($NewStr as $me)
{

foreach($NewStr as $check)
{
if($me == $check)
{
$flag++;
if($flag <= 1)
{
$arr[] = $check;
}


}
}

$flag = 0;
}


var_dump($arr);

output shuld be ‫‪the brown fox jumped over white‬‬

Quick and dirty, use an associative array.

 

<?php
$str = "the brown fox jumped over the white fox";

$NewStr = split(" ", $str);

$uniq = array();
foreach($NewStr as $me)
{
  $uniq[$me] = 1;
}

var_dump(array_keys($uniq));
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.