-1

I have a data array like this:

$data = array(1,2,3);

how to change the array like this:

$data = array('1','2','3');

Tanks Before

1
  • If your numbers are comming from variables you could do it like: $data = array(”{$a}”, ”{$b}”); Commented Jan 27, 2022 at 9:39

1 Answer 1

0

You have to change type of all array values, just like this

foreach ($data as $key => $val) {
  $data[$key] = (string) $val;
}

or

function convert2string($n)
{
    return (string) $n;
}

$a = [1, 2, 3];
$data = array_map('convert2string', $a);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.