drde3456 2013-06-17 11:42
浏览 22
已采纳

使用字符串创建关联数组

I read some words from a text file, storing each word as an array element using the file() function. Now I need to sort each word and create an associative array that stores the sorted strings as keys and the original strings as values like so :

$hash_table = array( 'sorted_string' => 'original string' );

I loop through every word read from the file and sort it in ascending order but when it comes to pushing it to the associative array, I am completely lost. Can anyone show me how to create the associative array ?

  • 写回答

3条回答 默认 最新

  • doujian1954 2013-06-17 11:56
    关注
    $a = array('green', 'yellow', 'red');//actual
    $b = array('green', 'yellow', 'red');
    sort($b); //sorted
    $c = array_combine($b, $a);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?