Hi I have an array using a code below
var selectedValues=new Array();
selectedValues=divisi.split(",");
and the result is
ITD, ITO, Keuangan, Sumber Daya Manusia
But I want to have a result like
"ITD", "ITO", "Keuangan", "Sumber Daya Manusia"
Do you know how to make it like that? thankyou
The split would return an array of strings itself, if that is the question. http://php.net/manual/en/function.split.php
Edit: Adding a more detailed answer:
<?php
$divisi = "ITD, ITO, Keuangan, Sumber Daya Manusia";
$selectedValues = array();
$selectedValues = split(",", $divisi);
var_dump($selectedValues)
?>
The script above returns the below array when run on http://phpfiddle.org/
array(4) { [0]=> string(3) "ITD" [1]=> string(4) " ITO" [2]=> string(9) " Keuangan" [3]=> string(20) " Sumber Daya Manusia" }
As pointed out split
is deprecated: http://php.net/manual/en/function.split.php . Please use explode
or str_split
Also your code looks like it is JavaScript and not proper PHP. So take care of that.
Try this: Working example
var divisi = ['ITD', 'ITO', 'Keuangan', 'Sumber Daya Manusia']; //you can use user defined array or direct variable divisi
console.log('"'+divisi.join('\",\"')+'"'); //"ITD","ITO","Keuangan","Sumber Daya Manusia"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.