我有這個PHP創建作爲$ jobs的作業數組。但是我想的鑰匙是[參考],而不是0,1,2等如何將新密鑰分配給PHP關聯數組
$xml_feed = new DOMDocument();
$xml_feed->load('http://jobs.recruitsosimple.com/job/762/xml');
$jobs = array();
foreach ($xml_feed->getElementsByTagName('job') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'ref' => $node->getElementsByTagName('referencenumber')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('url')->item(0)->nodeValue,
);
array_push($jobs, $item);
}
創建的陣列是:
Array
(
[0] => Array
(
[title] => Theatre Nurse
[ref] => MT29
[link] => http://jobs.com/job/1192/29
)
[1] => Array
(
[title] => Ward Nurse
[ref] => MT39
[link] => http://jobs.com/1192/762/39
)
)
但我想的鑰匙是
Array
(
[MT29] => Array
(
[title] => Theatre Nurse
[ref] => MT29
[link] => http://jobs.com/job/1192/29
)
[MT39] => Array
(
[title] => Ward Nurse
[ref] => MT39
[link] => http://jobs.com/1192/762/39
)
)
我該怎麼做?
您只需建立enties這樣的:'$工作[$參考] = $項目;'而不是arraypush – Jeff