getValueFields - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of getValueFields.php
- <?php
- $array = [
- 'qwe' => [
- 'rtz'
- ],
- 'asd' => [
- 'fgh'
- ],
- 'yxc' => [
- 'vbn'
- ]
- ];
- function getValueFieldsForeach(array $values) {
- foreach ($values as $value) {
- return array_keys($value);
- }
- }
- function getValueFieldsReset(array $values) {
- return array_keys(reset($values));
- }
- function getValueFieldsEasy(array $values) {
- return $values[array_keys($values)[0]];
- }
- print_r(getValueFieldsForeach($array));
- print_r(getValueFieldsReset($array));
- print_r(getValueFieldsEasy($array));