开发者

Extract key from array

开发者 https://www.devze.com 2023-04-08 16:10 出处:网络
I just w开发者_开发百科onder if i can get the keys from below code $keys = array_keys($_POST); //this will return all key

I just w开发者_开发百科onder if i can get the keys from below code

$keys = array_keys($_POST); //this will return all key
$key = array_key($_POS['username']) //i dont know this this is possible, im trying to get the 'username'

is it possible?


array_keys($_POST);

for the single key:

list($key) = array_keys($_POST);

or

reset($_POST);
$key = key($_POST);


slier, are you looking for

array_keys($_POST);

?


if(array_key_exists('username',$_POST)){
   $_POST['username'];
}

or

for ($_POST as $key=>$value){
   //Iterate and use $key
}


array_keys($_POST) 

is what you're looking for


You can get a list of all the keys with something like array_keys($_POST).

If you just want to know whether a "username" was posted, isset($_POST['username']) would work.

But if you're trying to take $_POST['username'] and know that its key was "username", you won't be able to reliably do that short of looping through the array like foreach ($_POST as $key => $value).

0

精彩评论

暂无评论...
验证码 换一张
取 消