public static function keyValue($list, $keyProperty=null, $valueProperty=null)
    {
        $index = array();
        foreach ($list as $i) {
            if ($keyProperty) {
                if (!$valueProperty) { 
                    throw new \InvalidArgumentException("Must set value property if setting key property");
                }
                $index[$i->$keyProperty] = $i->$valueProperty;
            }
            else {
                $key = current($i);
                next($i);
                $value = current($i);
                $index[$key] = $value;
            }
        }
        return $index;
    }
public static function keyValue($list, $keyProperty=null, $valueProperty=null)
    {
        $index = array();
        foreach ($list as $i) {
            if ($keyProperty) {
                if (!$valueProperty) { 
                    throw new \InvalidArgumentException("Must set value property if setting key property");
                }
                $index[$i->$keyProperty] = $i->$valueProperty;
            }
            else {
                $key = current($i);
                next($i);
                $value = current($i);
                $index[$key] = $value;
            }
        }
        return $index;
    }
public static function keyValue ( $ list , $ keyProperty = null , $ valueProperty = null ) { $ index = array ( ) ; foreach ( $ list as $ i ) { if ( $ keyProperty ) { if ( ! $ valueProperty ) { throw new \ InvalidArgumentException ( "Must set value property if setting key property" ) ; } $ index [ $ i -> $ keyProperty ] = $ i -> $ valueProperty ; } else { $ key = current ( $ i ) ; next ( $ i ) ; $ value = current ( $ i ) ; $ index [ $ key ] = $ value ; } } return $ index ; }
Create a one-dimensional associative array from a list of objects, or a list of 2-tuples.

@param object[]|array $list
@param string $keyProperty
@param string $valueProperty
@return array
Create a one - dimensional associative array from a list of objects or a list of 2 - tuples .