-1

I have values like

"34,37"

and I want to create array using this values, array like

array('34','37')

How to create such array if I have values.

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
S.A.
  • 57
  • 6

4 Answers4

3

hope this will help you :

you can use explode function if you have values as string;

  $string = '34,37';
  $data = explode(',',$string):
  print_r($data); /*output array*/

for more : http://php.net/manual/en/function.explode.php

Pradeep
  • 9,667
  • 13
  • 27
  • 34
1

Try this,

$val = "34,37"
$val = explode(',', $val);
print_r($val);

output of above array:

Array
(
  [0] => 34,
  [1] => 37
)
Smuuf
  • 6,339
  • 3
  • 23
  • 35
Vivek ab
  • 660
  • 6
  • 15
1

As per my comment, you should use preg_split function. for more details about preg_split function please read PHP manual and also you can use explode function Explode function PHP manual

<?php
      $string = '34,37';
      $keywords = preg_split("/[\s,]+/", $string);
      //OR $keywords = preg_split("/,/", $string); separated by comma only
      print_r($keywords);

you can check your desired Output here

Bilal Ahmed
  • 4,005
  • 3
  • 22
  • 42
1

If you have a string like this:

$str = "1,2,3,4,5,6";

And you want to convert it into array, just use explode()

$myArray = explode(',', $str);
var_dump($myArray);

Have a look here for more information

Abdullah Al Shakib
  • 2,034
  • 2
  • 15
  • 16