Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
词典编排-PHP_Php - Fatal编程技术网

词典编排-PHP

词典编排-PHP,php,Php,我有“解决方案”,如“4210503”、“01025433”。(只是一个例子) 如何得到字典最小解?这是什么意思?这个程序是用PHP编写的。我尝试通过“”分解它们,并在生成的数组上使用min()函数,但这并没有给出正确的解决方案 尝试自然排序顺序 $strVal1 = "4 2 10 5 0 3"; $arrVal1 = explode(" ", $strVal1); natsort($arrVal1); //will sort array as 0,2,3,4,5,10 $minVal

我有“解决方案”,如“4210503”、“01025433”。(只是一个例子)


如何得到字典最小解?这是什么意思?这个程序是用PHP编写的。我尝试通过“”分解它们,并在生成的数组上使用
min()
函数,但这并没有给出正确的解决方案

尝试自然排序顺序

$strVal1 = "4 2 10 5 0 3";

$arrVal1 = explode(" ", $strVal1); 

natsort($arrVal1); //will sort array as 0,2,3,4,5,10

$minVal = $arrVal1[0]; 

echo $minVal; //should return 0
编辑:根据您的评论

//let's suppose you have an array of string values as in your example
//and $strVal1 = ""4 2 10 5 0 3", $strVal2 = "0 10 2 5 4 3" and so on
$strVals = array($strVal1, $strVal2 , $strVal3 , ... ,$strValN)

//just sort it naturally and there you have it :)
natsort($strVals); 

//the smallest element is first
echo $strVals[0]; 

PHP natsort()函数引用-

hmmmm…字典顺序指字典顺序;在数字的情况下,如果你有101,1和11,一个普通的排序会产生101,11,但是一个自然的排序(字典)是你和我理解它的方式:1,11,101我不想对单个数字进行排序,我想要按字典顺序排列的多个字符串