Loop through each key and value of php multidimensional array -


i have following array:

<pre>array (     [student] => array         (             [admission_no] => array                 (                     [isempty] => please enter admission no                 )              [admission_date] => array                 (                     [isempty] => please enter admission date                 )          )      [student_personal_details] => array         (             [first_name] => array                 (                     [isempty] => please enter first name                 )              [gender] => array                 (                     [isempty] => please select gender                 )              [birth_date] => array                 (                     [isempty] => please enter birth date                 )          )      [student_gardian_details] => array         (             [first_name] => array                 (                     [isempty] => please enter gardian first name                 )          )      [student_education_details] => array         (             [roll_no] => array                 (                     [isempty] => please enter pin code                 )          )  ) 

i want strings in array using while loop. mean keys of whole array not array itself.

i tried following code:

private function getinternalerorrstring($array) {         while (list($var, $val) = each($array)) {             if(is_array($var)) {                 $this->getinternalerorrstring($var);             } else {                 return $val;             }         }     } 

can have better idea?

alternatively, use spl recursivearrayiterator values. consider example:

$values = array( 'student' => array( 'admission_no' => array('isempty' => 'please enter admission no'), 'admission_date' => array('isempty' => 'please enter admission date'), ), 'student_personal_details' => array( 'first_name' => array('isempty' => 'please enter first name'), 'gender' => array('isempty' => 'please enter gender'), 'birth_date' => array('isempty' => 'please enter birth date'), ), 'student_gardian_details' => array( 'first_name' => array('isempty' => 'please enter gardian first name'), ), 'student_education_details' => array( 'roll_no' => array('isempty' => 'please enter pin code'), ),);  $iterator = new recursiveiteratoriterator(new recursivearrayiterator($values)); foreach($iterator $key => $value) {     $data[] = $value; } 

sample output:

array (     [0] => please enter admission no     [1] => please enter admission date     [2] => please enter first name     [3] => please enter gender     [4] => please enter birth date     [5] => please enter gardian first name     [6] => please enter pin code ) 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -