我想根據以下XML按薪水順序排列一個玩家數組。請注意,我已經用薪水對籃球隊進行了排序。PHP:使用XML字符串創建數組
<?php
$string = <<<EOS
<Sports_Team>
<Basketball>
<Players>Tom, Jack, Sue</Players>
<salary>4</salary>
</Basketball>
<Basketball>
<Players>Josh, Lee, Carter, Bennett</Players>
<salary>6</salary>
</Basketball>
<Basketball>
<Players>Mary, Jimmy, Nancy</Players>
<salary>44</salary>
</Basketball>
</Sports_Team>
EOS;
$xml = simplexml_load_string($string);
$trees = $xml->xpath('/Sports_Team/Basketball');
function sort_trees($t1, $t2) {
return strcmp($t1['salary'], $t2['salary']);
}
usort($trees, 'sort_trees');
var_dump($trees);
?>
我想從$trees
製作一系列玩家。如何創建一個數組對象,使得:
[0]-> Mary, Jimmy, Nancy
[1]-> Josh, Lee, Carter, Bennett
[2]-> Tom, Jack, Sue
而且,一旦我存儲我的數組我怎麼把它打印出來有多大嗎?
我修復了一個問題我的第一個例子; '$ users'被用來代替'$ trees'。我也回答了關於按玩家數量排序的部分:) – Will