note 113058 added to function.array-walk-recursive

From: Date: Fri, 23 Aug 2013 13:27:59 +0000
Subject: note 113058 added to function.array-walk-recursive
Groups: php.notes 
Request: Send a blank email to php-notes+get-196060@lists.php.net to get a copy of this message
Simple array_walk_recursive: // var example $myArray = Array( Array('keyA1' => ' textA1 ', 'keyA2' => ' textA2 '), Array('keyB1' => ' textB1 ', 'sub' => Array('keyB1_sub1' => ' textB1_sub1 '), Array('keyB1_sub2' => ' textB1_sub2 ') ), Array('keyC1' => ' textC1 ', 'keyC2' => ' textC2 '), Array('keyD1' => ' textD1 ', 'keyD2' => ' textD2 '), Array('keyE1' => ' textE1 ', 'keyE2' => ' textE2 ') ); // function for "trim" (or your function, use same structure) function trimming($data) { if (gettype($data) == 'array') return array_map("trimming", $data); else return trim($data); } // get array $myArray = array_map("trimming", $myArray); // show array trimmed var_dump($myArray); /* RESULT array (size=5) 0 => array (size=2) 'keyA1' => string 'textA1' (length=6) 'keyA2' => string 'textA2' (length=6) 1 => array (size=3) 'keyB1' => string 'textB1' (length=6) 'sub' => array (size=1) 'keyB1_sub1' => string 'textB1_sub1' (length=11) 0 => array (size=1) 'keyB1_sub2' => string 'textB1_sub2' (length=11) 2 => array (size=2) 'keyC1' => string 'textC1' (length=6) 'keyC2' => string 'textC2' (length=6) 3 => array (size=2) 'keyD1' => string 'textD1' (length=6) 'keyD2' => string 'textD2' (length=6) 4 => array (size=2) 'keyE1' => string 'textE1' (length=6) 'keyE2' => string 'textE2' (length=6) */ ---- Server IP: 69.147.83.199 Probable Submitter: 200.18.252.83 ---- Manual Page -- http://php.net/manual/en/function.array-walk-recursive.php Edit -- https://master.php.net/note/edit/113058 Del: integrated -- https://master.php.net/note/delete/113058/integrated Del: useless -- https://master.php.net/note/delete/113058/useless Del: bad code -- https://master.php.net/note/delete/113058/bad+code Del: spam -- https://master.php.net/note/delete/113058/spam Del: non-english -- https://master.php.net/note/delete/113058/non-english Del: in docs -- https://master.php.net/note/delete/113058/in+docs Del: other reasons-- https://master.php.net/note/delete/113058 Reject -- https://master.php.net/note/reject/113058 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#196060) next »