Php 如何将数组对象移动到位置0

Php 如何将数组对象移动到位置0,php,arrays,sorting,Php,Arrays,Sorting,我目前正在使用一个数组,我需要知道如何将该数组中的对象移动到第一个位置,位置[0] 我有这个 <?php $extensions = array( '.com' => array('whois.verisign-grs.com','No match for'), '.info' => array('whois.afilias.net','NOT FOUND'), '.net' => a

我目前正在使用一个数组,我需要知道如何将该数组中的对象移动到第一个位置,位置[0]

我有这个

<?php    
$extensions = array(
        '.com'      => array('whois.verisign-grs.com','No match for'),
        '.info'     => array('whois.afilias.net','NOT FOUND'),  
        '.net'      => array('whois.crsnic.net','No match for'),
        '.co.uk'    => array('whois.nic.uk','No match'),        
        '.nl'       => array('whois.domain-registry.nl','is free'),
    );
?>

将嵌套数组合并到较大的数组中:

$ext = array(
    '.com'   => array('whois.verisign-grs.com','No match for'),
    '.info'  => array('whois.afilias.net','NOT FOUND'),  
    '.net'   => array('whois.crsnic.net','No match for'),
    '.co.uk' => array('whois.nic.uk','No match'),        
    '.nl'    => array('whois.domain-registry.nl','is free'),
);

$ext = array_merge( Array( ".net" => $ext[".net"] ), $ext );

演示:

删除它,然后再次添加

$v = $extensions['.net'];
unset($extensions['.net']);
$extensions['.net'] = $v;

将条目移动到位置0后保持数组的顺序是否重要?是。因为顶级TLD是最常见的onesok,所以您可以使用前面提到的array_unshift将元素前置到开头。这不适用于我,因为您有两个相同的TLD。我唯一想做的就是将某个数组对象移动到位置0,而不影响others@GuidoVisser我明白你在说什么;我已经更新了上面的答案。
$v = $extensions['.net'];
unset($extensions['.net']);
$extensions['.net'] = $v;