<?
function choise($index){
$types=array("model", "brand");
if (
!((count($index)==2 and in_array($type=$index[0], $types) and ($id=is_int($index[1])?$index[1]:0 and !$keyword=false or $keyword=$index[1] and !$id=false))
or (count($index)==1 and in_array($type=key($index), $types) and (($id=is_int(current($index))?current($index):0 and !$keyword=false) or ($keyword=current($index) and !$id=false)))
or ($type=false or $id=false or $keyword=false))
){
echo 'incorrect format'."\n";
return;
}
echo '$type=';
var_dump($type);
echo '$keyword=';
var_dump($keyword);
echo '$id=';
var_dump($id);
echo '-------------'."\n";
}
choise(array('model'=>5));
choise(array('model', 5));
choise(array('model', 'bmw'));
choise(array('model'=>'bmw'));
choise(array('m'=>'bmw'));
choise(array('m', 'bmw'));
choise(array('model', 'bmw', 5));
?>