original_string: public static function index_by_first_val(array $ar): array
    {
      if ( empty($ar) || !isset($ar[0]) || !\count($ar[0]) ){
        return $ar;
      }
      $cols = array_keys($ar[0]);
      $idx = array_shift($cols);
      $num_cols = \count($cols);
      $res = [];
      foreach ( $ar as $d ){
        $index = $d[$idx];
        unset($d[$idx]);
        $res[$index] = $num_cols > 1 ? $d : $d[$cols[0]];
      }
      return $res;
    }
code: public static function index_by_first_val(array $ar): array
    {
      if ( empty($ar) || !isset($ar[0]) || !\count($ar[0]) ){
        return $ar;
      }
      $cols = array_keys($ar[0]);
      $idx = array_shift($cols);
      $num_cols = \count($cols);
      $res = [];
      foreach ( $ar as $d ){
        $index = $d[$idx];
        unset($d[$idx]);
        $res[$index] = $num_cols > 1 ? $d : $d[$cols[0]];
      }
      return $res;
    }
code_tokens: public static function index_by_first_val ( array $ ar ) : array { if ( empty ( $ ar ) || ! isset ( $ ar [ 0 ] ) || ! \ count ( $ ar [ 0 ] ) ) { return $ ar ; } $ cols = array_keys ( $ ar [ 0 ] ) ; $ idx = array_shift ( $ cols ) ; $ num_cols = \ count ( $ cols ) ; $ res = [ ] ; foreach ( $ ar as $ d ) { $ index = $ d [ $ idx ] ; unset ( $ d [ $ idx ] ) ; $ res [ $ index ] = $ num_cols > 1 ? $ d : $ d [ $ cols [ 0 ] ] ; } return $ res ; }
docstring: Creates an associative array based on the first array's value.
  
  @param array $ar
  @return array
docstring_tokens: Creates an associative array based on the first array s value .