perl VS php数据结构比较

——perl array—–                                                                    ——php array——
@a=();                                                                                     $a=array();
@a1=(‘aa’,1,2);                                                                       $a1=array(‘aa’,1,2);
@a2=0..9;                                                                               $a2=range(0,9);
$a[0]=’sth’;                                                                              $a[0]=’sth’;
$len=scalar @a; or $len=@a;                                                 $len=count($a);
@a3=(‘bb’,@a1,@a2);                                                            $a3=array_merge(‘xx’,$a1,$a2);
$a[@a]=’new’; #push                                                              $a[]=’new’; #push
push                                                                                        array_push
pop                                                                                          array_pop
shift                                                                                         array_shift
unshift                                                                                     array_unshift
splice                                                                                      array_splice
foreach (@a) {…}                                                                    foreach ($a as $i) {…}
——perl hash——                                                                  ——php hash——
%h=();                                                                                    $h=array();
%h=(‘x’=>’y’,’z’=>’w’);                                                             $h=array(‘x’=>’y’,’z’=>’w’);
$h{‘x’}=1;                                                                                $h[‘x’]=1;
while (($key,$value)=each(%h)){…}                                       foreach ($h as $key=>$value){…}
@k=keys(%h);                                                                       $k=array_keys($h);
@v=values(%h);                                                                    $v=array_values($h);
delete $h{‘x’};                                                                         unset($h[‘x’]);
——perl数据结构——                                                            ——php数据结构——
%h=(‘a’=>1,’b’=>2);                                                               $h=array(‘a’=>1,’b’=>2);
@a=(‘one’,’two’,’three’);                                                         $a=array(‘one’,’two’,’three’);
@mix=(%h,@a,[10..20],{‘x’=>15,’y’=>30});                           $mix=array($h,$x,range(10,20),array(‘x’=>15,’y’=>30));
$mix[0]->{‘b’} #2                                                                    $mix[0][‘b’] #2
$mix[0]{‘b’} #2
$mix[2]->[2] #12                                                                    $mix[2][2] #12
$mix[2][2] #12
%value=(’00’=>[],’01’=>[],’02’=>[]);                                        $value=array(’00’=>[],’01’=>[],’02’=>[]);