在php中获取数组的索引

I have an array that contains the following:

$code_ids
 [138]=>
  string(0) "asdsad"
  [126]=>
  string(0) ""
  [163]=>
  string(0) "asdasd"
  [162]=>
  string(0) ""
  [135]=>
  string(0) "awawawaw"
  [59]=>
  string(0) ""
  [63]=>
  string(0) ""
  [70]=>
  string(0) ""
  [146]=>
  string(0) ""
  [155]=>
  string(0) ""
  [66]=>
  string(0) ""

I want to get a hold of all indexes if it contains anything. How do you do this? I tried

foreach($code_ids as $code_id) {
  if(!empty($code_id)) {
     $index[] = $code_id;
  }
}

The problem in this is that it gets its value. I just want the index.

Try it

array_keys(         // 2. returns keys as new array
    array_filter(   // 1. removes all empty items
        $code_ids));

array_filter, array_keys