Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

A4Family's avatar

PHP array_map() help

I would like to ask. Would you like to help me? I have a controller in laravel

This is my collections

$milestones = $this->getmilestones();
dump($milestones);

and the value is

array:3 [▼
  0 => "["109"
  1 => "110"
  2 => "111"]"
]

And I try this code based on answer in Here So, I have code like this

array_unshift($milestones, $milestones[0]);
unset($milestones[0]);
dump($milestones);

and the value is (index was changed)

array:3 [▼
  1 => "["109"
  2 => "110"
  3 => "111"]"
]

So, after unshift the collections, I try to use array_map to convert array of string to array of integer.

$milestones = array_map('intval', $milestones);
dump($milestones);

But, I still got the same value. The first index return 0 like this

array:3 [▼
  1 => 0
  2 => 110
  3 => 111
]

What should I do? Thanks in advanced

0 likes
2 replies
tisuchi's avatar
tisuchi
Best Answer
Level 70

@a4family

What if you try this?

$milestones = str_replace(array('[', ']', '"'),'',$milestones);

Since you try to remove square brackets and double-quotes.

8 likes

Please or to participate in this conversation.