2

How could I get only the entire first row from an array. (I use Laravel)

For example when I say:

$request-all();

I receive:

array:2 [
  "email" => "[email protected]"
  "password" => "adms|Wh"
]

I want to receive:

email
password
2

2 Answers 2

4

If I understood your question correctly, you want something like this:

$keys = array_keys($array);
foreach ($keys as $key){
    echo $key;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Or simply foreach($array as $key => $value) { echo $key }
0

You can use the PHP array_keys() function to get all the keys out of an associative array.

$array = array("email"=>"[email protected]", "password"=>"adms|Wh");

Get keys from $array array

 print_r(array_keys($array));

You can also use the PHP foreach loop to find or display all the keys, like this:

Loop through $array array

foreach($array as $key => $value){
    echo $key . " : " . $value . "<br>";
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.