简体   繁体   English

如何获得仅具有不同键的输出数组?

[英]How can i get output array having only different key?

I have following two array 我有以下两个数组

 $array1 = array("product_a" => "Nokia1", "product_b" => "Nokia11", "product_c" => "Nokia111", "Nokia1111"); $array2 = array("product_a" => "Nokia1", "Samsung", "Nokia1111"); 

I want to compare these both array and want output as having different keys 我想比较这两个数组,并希望输出具有不同的键

Like my output as below 就像我的输出如下

 Array ( [product_b] => Nokia11 [product_c] => Nokia111 [0] => Nokia1111 ) 

is there any default php method available to compare? 有没有可用的默认php方法进行比较?

I think that you can try 我认为你可以尝试

 function key_compare_func($a, $b) { if ($a === $b) { return 0; } return ($a > $b)? 1:-1; } 

You can get some reference with following link too, 您也可以通过以下链接获得一些参考,

http://questionnanswer.com/questions/view_question/80/category_list:2/how-can-get-different-key-array ? http://questionnanswer.com/questions/view_question/80/category_list:2/how-can-get-different-key-array吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM