src/bbn/x.php
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;
  }
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;
  }
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 ; }
Creates an associative array based on the first array's value.

@param array $ar
@return array
Creates an associative array based on the first array s value .