PHP shortest/longest string in array
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an array like this $data = array( "163", "630", "43", "924", "4", "54" ); How can I select the smallest and largest values from it according to string length NOT number value. (for this example it is 1 (smallest) and 3 (largest) . 回答1: Seems like you should use an array_map() // Convert array to an array of string lengths $lengths = array_map('strlen', $data); // Show min and max string length echo "The shortest is " . min($lengths) . ". The longest is " . max($lengths); Note that the $lengths array is unsorted, so you can easily