0

i am using array_unique(); to unique array values it perfectly works. but when if getting value form offset it gives error. mission offset.

my array before using array_unique();

$tags_array = explode(',', $tagss);

it gives result :

Array ( [0] => katha [1] => pooja [2] => singer [3] => katha [4] => katha [5] => pooja [6] => archana [7] => dance )

after using array_unique();

$tags_array = array_unique($tags_array);

it gives result :

Array ( [0] => katha [1] => pooja [2] => singer [6] => archana [7] => dance )

i am using it in loop:

for($i=0;$i<count($tags_array);$i++){
    echo '<a class="label label-primary tags" href="'.base_url().'home/tag/'.$tags_array[$i].'">'.ucfirst($tags_array[$i]).'</a>';
}

it gives error:

Severity: Notice

Message: Undefined offset: 3

Filename: views/search.php

Line Number: 178

how to make serial wise offset. like

Array ( [0] => katha [1] => pooja [2] => singer [3] => archana [4] => dance )

0

1 Answer 1

0

do the fact that you have not more the array index based on sequential number instead of for you could use foreach

foreach($tags_array as $key => $value{
   echo '<a class="label label-primary tags" href="'.
         base_url().'home/tag/'.$tags_array[$i].'">'.
             ucfirst($value).'</a>';
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.