Skip to content

Instantly share code, notes, and snippets.

@ppshobi
Created September 21, 2017 04:57
Show Gist options
  • Save ppshobi/1cfec91e7a37fe6f30f7438bc37d8f1c to your computer and use it in GitHub Desktop.
Save ppshobi/1cfec91e7a37fe6f30f7438bc37d8f1c to your computer and use it in GitHub Desktop.
array_walk_recursive - Example
<?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