0

I removed duplicated values from array with array_unique

    $keys = preg_split('/\r\n|[\r\n]/', $request->text);
    $keys = array_unique($keys);
    $keys_count = count($keys);

It shows like this

array:6 [▼
 0 => "1"
  3 => "2"
  4 => "3"
  5 => "4"
  6 => "5"
  7 => "6"
]

My for loop looks like this:

for ($i=0; $i < $keys_count; $i++)
{
   print_r($keys[$i]);
}

I'm getting undefined offset 1.

How can I change keys again from 0, 1, 2.. to the end of array..

What I also tried

dd(array_fill_keys([$i], $keys));

Shows

array:1 [▼
 0 => array:6 [▼
    0 => "1"
    3 => "2"
    4 => "3"
    5 => "4"
    6 => "5"
    7 => "6"
  ]
]
Maren Maren
  • 59
  • 1
  • 2
  • 8

0 Answers0