PHP基础数组取值解决思路

WBOY
Release: 2016-06-13 11:15:23
Original
856 people have browsed it

PHP基础数组取值
数组1 ( [0] => company [1] => online [2] => call [3] => banner [4] => archive ) 
数组2 ( [0] => company [1] => banner [2] => archive [3] => logo [4] => movie [5] => product ) 

现有数组1,2,我该如何才能得出
数组3( [0] => online [1] => call ) 
数组4( [0] => logo [1] => movie [2] => product ) 

php PHP基础数组取值
------解决方案--------------------
$a1 = array('company', 'online', 'call', 'banner', 'archive'); <br />$a2 = array('company', 'banner', 'archive', 'logo', 'movie', 'product');<br /> <br />print_r(array_diff($a1, $a2));<br />print_r(array_diff($a2, $a1));<br />
Copy after login
Array
(
[1] => online
[2] => call
)
Array
(
[3] => logo
[4] => movie
[5] => product
)

------解决方案--------------------
<br />	$ar1 = array('company', 'online', 'call', 'banner', 'archive'); <br />	$ar2 = array('company', 'banner', 'archive', 'logo', 'movie', 'product');<br />	$ar3=array_slice($ar1,1,2);<br />	$ar4=array_slice($ar2, 3);<br />	print_r($ar3);<br />	print_r($ar4);<br />
Copy after login

------解决方案--------------------
楼上两位的结果相同,但想法完全不同
#1求差集
#2求片段
LZ没说清目的,所以选用的时候要搞清你的需求……
------解决方案--------------------
谢谢分享。。。
------解决方案--------------------
不知道你的意图
------解决方案--------------------
lz的意思是什么?是不是匹配不同的公司?
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template