Created
September 21, 2017 04:57
-
-
Save ppshobi/1cfec91e7a37fe6f30f7438bc37d8f1c to your computer and use it in GitHub Desktop.
array_walk_recursive - Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$array = [ | |
'a' => [ | |
'z' => 'abcs ', | |
'y' => ' xzsy ', | |
'x' => 'abc xyz', | |
'w' => [ | |
'elem1' => ' gasd fsdf ', | |
'elem2' => 'ash fhakjs d ' | |
] | |
], | |
'b' => ' xyz ', | |
'c' => 'pqr s t' | |
]; | |
function trimArrayElements(&$item) | |
{ | |
$item = trim($item); | |
} | |
echo ("\n =============Un Trimmed Array ================\n"); | |
var_dump($array); | |
array_walk_recursive($array, 'trimArrayElements'); | |
echo ("\n ============= Trimmed Array ================\n"); | |
var_dump($array); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment