PHP 37
Array in ein PHP5 Objekt konvertieren By micha on 9th July 2018 12:19:43 PM
  1. //Die Funktion arrayToObject() durchläuft rekursiv ein Array und gibt anschließend das Array als PHP5 Objekt zurück.
  2.  
  3. function arrayToObject( $array ) {
  4.    
  5.   $object = new stdClass();
  6.  
  7.   foreach( $array as $key => $value ) {
  8.     if( is_array( $value ) ) {
  9.       $object->$key = arrayToObject( $value );
  10.     }
  11.     else {
  12.       $object->$key = $value;
  13.     }
  14.  
  15.   }
  16.   return $object;
  17.  
  18. }

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.