please refer to the code below.
$dArr = '<script>document.write(volunteerDist);</script>';
$dArr gets the value of volunteerDist. echo $dArr prints the value 4.1,9.4,2.3,4.7,9.1,14.7,3.2,7.1,4.1,0.5
I wanted to split this into elements in an Array so I used:
$dArr = preg_split("/,/", $dArr);
But $dArr is an array with only one element, which is all of the values.. meaning no preg_split took place. I also tried
$temp=explode(",", $dArr);
but still did not work.
I tried to paste the value (i.e. the numbers above) and preg_split it directly
$temp=explode(",", '4.1,9.4,2.3,4.7,9.1,14.7,3.2,7.1,4.1,0.5');
and it was successful. What is wrong? TAKE NOTE that when I echo $dArr, the numbers are printed.
,you should useexplode()anyway. The performance loss ofpreg_split()is negligible, but if you're doing this is any sort of iteration, you may as well benefit from the brevity and speed ofexplode().=is executed on the front end ... have you checked$dArris not empty ???