怎样用php取一个数组中的第二个cookie

WBOY
Release: 2016-06-06 20:40:19
Original
1142 people have browsed it

<code>Array ( [ASPSESSIONIDSQSQBTCD] => BEEFLOIDMLKMMBCCBEMHBKND [ASPSESSIONIDAQSRDDBA] => BIPEIOLDJKAPKMCDBNECGKMK )
</code>
Copy after login
Copy after login

如上所示:怎样用 php 取到 Array([ASPSESSIONIDAQSRDDBA] => BIPEIOLDJKAPKMCDBNECGKMK)

回复内容:

<code>Array ( [ASPSESSIONIDSQSQBTCD] => BEEFLOIDMLKMMBCCBEMHBKND [ASPSESSIONIDAQSRDDBA] => BIPEIOLDJKAPKMCDBNECGKMK )
</code>
Copy after login
Copy after login

如上所示:怎样用 php 取到 Array([ASPSESSIONIDAQSRDDBA] => BIPEIOLDJKAPKMCDBNECGKMK)

array_slice($arr, 1, 1);

<code><?php $arr = array(); //your cookies

$val = array_values($arr);
$cookie = $val[1];
</code></code>
Copy after login

方法一:只取value
next($a);

$v = current($a);

方法二:取key和value
$ak=array_keys($a);
$av = array_values($a);
$k = $ak[1];
$v = $av[1];

如果题主想要强调“保留key构建一个新的数组”,建议这样写

<code>$arr = ['a'=>'b', 'c'=>'d'];
$keys = array_keys($arr);

print_r([$keys[1] => $arr[$keys[1]]]);
</code>
Copy after login

<code>$arr[1]
</code>
Copy after login

<code>unset($arr[ASPSESSIONIDSQSQBTCD]);
</code>
Copy after login
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!