-4

How can i convert string ids

$ids = '8552479333,8552438544,';

to look like an array

["8552479333","8552438544"]

I tryed :

$ids = (explode(",",$ids,-1));

but this gives me :

Array ( [0] => 8552479333 [1] => 8552438544)
3
  • $array = implode(',', $string); Commented Dec 29, 2016 at 10:42
  • Explode worked. So I'm confused as to what you want Commented Dec 29, 2016 at 10:42
  • i want to pass this id-s in post request as a data Commented Dec 29, 2016 at 10:43

2 Answers 2

1

This is a very specific way of formatting. You could miss use the json encoding routines to get the exact result you are looking for:

<?php
$ids = '8552479333,8552438544,';
$string = json_encode(explode(',', $ids, -1));
var_dump($string);

The output obviously is:

string(27) "["8552479333","8552438544"]"
Sign up to request clarification or add additional context in comments.

1 Comment

alright , i was missing json_encode . Thanks
0
<?php
$ids = '8552479333,8552438544,';
$ids = json_encode(explode(',', $ids, -1));
print_r($ids);
?>

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.