I have this array
Array
(
[281] => Array
(
[0] => 1
[1] => 10
[2] =>
[3] =>
[4] => 1
)
)
how do i get the first element of this array if i dont know that the key is 281
i figured this would work but no go
$my_array[0]
Undefined offset
Supposed that you haven't traversed the array yet - use key()
function to get the key value, and current
for item value, or move pointer to the begin with reset()
var_dump(key($my_array));
var_dump(current($my_array));
多种方法,这是一种可行的方法:
$output = array_slice( $inputArr, 0, 1 );
use reset()
. It will give the first element but will reset the internal pointer of the array though
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.