数组问题

WBOY
WBOYOriginal
2016-06-23 13:20:04923browse

请问 如何将一个数组中类似的值重新分成一个数组
例如{h1.jpg,h3.jpg,A1.jpg,h2.jpgB1.jpg,B2.jpg,A2.jpg,C1.jpg}
怎么按前缀分成  即 h一个数组 A B C各一个数组


回复讨论(解决方案)

$ar = array('h1.jpg', 'h3.jpg', 'A1.jpg', 'h2.jpg', 'B1.jpg', 'B2.jpg', 'A2.jpg', 'C1.jpg');foreach($ar as $v) $res[$v{0}][] = $v;print_r($res);
Array(    [h] => Array        (            [0] => h1.jpg            [1] => h3.jpg            [2] => h2.jpg        )    [A] => Array        (            [0] => A1.jpg            [1] => A2.jpg        )    [B] => Array        (            [0] => B1.jpg            [1] => B2.jpg        )    [C] => Array        (            [0] => C1.jpg        ))
分成单独变量
extract($res);print_r($h);
Array(    [0] => h1.jpg    [1] => h3.jpg    [2] => h2.jpg)

请问 如何将一个数组中类似的值重新分成一个数组
例如{h1.jpg,h3.jpg,A1.jpg,h2.jpgB1.jpg,B2.jpg,A2.jpg,C1.jpg}
怎么按前缀分成  即 h一个数组 A B C各一个数组



谢谢大神!!!
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn