Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

recursive code to iterate the stdClass object

<?php
   // Create new stdClass Object
	$init = new stdClass;

	// Add some test data
	$init->foo = "2019-02-15T11:12:28";
	$init->bar = new stdClass;
	$init->bar->baaz = "Testing&nbsp<the";
	$init->bar->fooz = new stdClass;
	$init->bar->fooz->baz = "Testing<> again";
	$init->foox = "Just<> test";

	
	
	
	function clean($string) {
      return preg_replace("/[^a-zA-Z0-9_\s]/", "", $string);
    }
	function striploop($obj){
	    $stipfields=['FirstName','LastName','MailingStreet','MailingCity'];
    	foreach($obj as $key => $item) {
           
            if(is_object($item) || is_array($item))
            striploop($item);
            if(is_string($item) && in_array($key,$stipfields))
            $obj->$key=clean($item);
          }
      
      return $obj;
	}
	
	// Print objects and array
	print_r(striploop($init));

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.