Answer the question
In order to leave comments, you need to log in
How to trim values in a multidimensional array?
Hey! I have an array like this:
Array
(
[servers] => Array
(
[4] => Array
(
[address] => xxxx
[protocol] => 48
[hostname] => xxxxx
[appid] => 10
(
[0] => Array
(
[player_id] => 0
[nick] => xxxxx
[score] => 2
[time_int] => 2680
[time_gmt] => 44:40
)
)
)
)
)
Answer the question
In order to leave comments, you need to log in
Here in 3 lines
array_walk_recursive($your_array, function(&$value){
$value = substr($value, 0, 3); // или что там вы подразумеваете под обрезанием
});
I suspect that recursion is needed.
An example algorithm might look like this:
function Circumcision($arr, $size) // :-)
{
$arr = array_slice($arr, 0, $size);
foreach($arr as $item)
{
if(is_array($item))
{
$item = Circumcision($item, 1); // привык к ооп, если что я не виноват :)
}
}
return $arr;
}
$input = array("a", "b", "c");
$result = Circumcision($input, 1);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question