PHP函数

数组函数

1.键值互换

array_flip(array)

  例子

<?php      
$a=array(0=>"Dog",1=>"Cat",2=>"Horse");
print_r(array_flip($a));
?>

输出结果

Array ( [Dog] => 0 [Cat] => 1 [Horse] => 2 )

2.二维数组某值转换为键

$array = array(
    array(‘id‘=>‘3‘,‘name‘=>‘tom‘),
    array(‘id‘=>‘5‘,‘name‘=>‘jerry‘),
    array(‘id‘=>‘24‘,‘name‘=>‘spike‘)
);
 
$newArray1 = array_column($array,NULL,‘id‘);
var_dump($newArray1);
//结果
array(
    ‘3‘=>array(‘id‘=>‘3‘,‘name‘=>‘tom‘),
    ‘5‘=>array(‘id‘=>‘5‘,‘name‘=>‘jerry‘),
    ‘24‘=>array(‘id‘=>‘24‘,‘name‘=>‘spike‘)
)
 
$newArray2 = array_column($array,NULL,‘name‘);
var_dump($newArray2);
//结果
array(
    ‘tom‘=>array(‘id‘=>‘3‘,‘name‘=>‘tom‘),
    ‘jerry‘=>array(‘id‘=>‘5‘,‘name‘=>‘jerry‘),
    ‘spike‘=>array(‘id‘=>‘24‘,‘name‘=>‘spike‘)
)

 

PHP函数

上一篇:BMZCTF WEB_ezeval


下一篇:【前端】使用weinre对手机、微信浏览器页面调试