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.



Your result can be seen below.

Result of php executing





Full code of getValueFields.php

  1. <?php
  2. $array = [
  3.     'qwe' => [
  4.         'rtz'
  5.     ],
  6.     'asd' => [
  7.         'fgh'
  8.     ],
  9.     'yxc' => [
  10.         'vbn'
  11.     ]
  12. ];
  13.  
  14. function getValueFieldsForeach(array $values) {
  15.     foreach ($values as $value) {
  16.         return array_keys($value);
  17.     }
  18. }
  19.  
  20. function getValueFieldsReset(array $values) {
  21.     return array_keys(reset($values));
  22. }
  23.  
  24. function getValueFieldsEasy(array $values) {
  25.     return $values[array_keys($values)[0]];
  26. }
  27.  
  28. print_r(getValueFieldsForeach($array));
  29. print_r(getValueFieldsReset($array));
  30. print_r(getValueFieldsEasy($array));
  31.  
File Description
  • getValueFields
  • PHP Code
  • 17 Jan-2020
  • 549 Bytes
You can Share it: