如何根据另一个数组值删除一个数组索引。例如-
Array1
(
[0] => @@code
[1] => @@label
[2] => @@name
[3] => @@age
)
Array2
(
[0] => 123jj
[1] => test
[2] => john
[3] => 45
)
Array3
(
[0] => 2 #2 is index to be unset in array1 and array2
[1] => 3 #3 is index to be unset in array1 and array2
)
我有 3 个数组,我想使用 php 在 array3 的值基础上取消设置数组 1 和 array2 索引。我如何使用unset()方法?
unset($array1,$array3) #this is wrong, but some thing like that
unset($array2,$array3)
没有出圈。
我应该得到
Array1
(
[0] => @@code
[1] => @@label
)
Array2
(
[0] => 123jj
[1] => test
)
您问了类似的问题,并在得到答案后将其删除:
从另一个数组的值中取消设置数组索引?
$firstArray = array( 0 => '@@code' ,1 => '@@label' ,2 => '@@name' ,3 => '@@age' );
$keysArray = array( 0 ,1 );
$resultArray = array_diff_key( $firstArray ,array_flip( $keysArray ) );
var_dump( $resultArray );
也许你需要这个?
foreach($array3 as $tmp){
unset($array1[$tmp]);
unset($array2[$tmp]);
}