There are a lot of problems in what you’re doing.
See the first case:
$poligono = array( "-22.8919, -43.1272", "-22.8652, -43.0954" );
|_____valor 1______| |_____valor 2______|
You are clearly creating an array with two elements.
Let’s go to the second case:
$poligono = array( $poli );
|_valor 1_|
Similarly, you are clearly creating an array with only one value.
See an example like your second case:
$poligono = array( '"-22.8919, -43.1272", "-22.8652, -43.0954"' );
|__________________valor 1_________________|
This way you will get the same result as the previous example. A value only, at zero position.
If you want to place values in separate positions, you have to provide them separately:
$valor1 = "-22.8919, -43.1272";
$valor2 = "-22.8652, -43.0954";
$poligono = array( $valor1, $valor2 );
Basically PHP will do what you tell it to do. If sent by a value, it obeys. If sent by two, also obeys.
As for this here:
$poli = '"-22.8919, -43.1272", "-22.8652, -43.0954"';
You are creating a single value, between simple quotes '
. If you put it in an array, it will remain a single value. It all depends on where you take the value, to see the best way to split, or to use split.
If you really need to do a gambit, one solution is this:
$poli = '"-22.8919, -43.1272", "-22.8652, -43.0954"';
$poli = str_replace( ' ', '', $poli );
$poli = str_replace( '","', '"|"', $poli );
print_r ( $poligono = explode( '|', $poli ) );
And if you don’t want the quotes in the result:
$poli = '"-22.8919, -43.1272", "-22.8652, -43.0954"';
$poli = str_replace( ' ', '', $poli );
$poli = str_replace( '","', '"|"', $poli );
$poli = str_replace( '"', '', $poli );
print_r ( $poligono = explode( '|', $poli ) );
But I don’t recommend this solution. The correct solution is to take the values separately from DB, and use separately in the array().
Hello. basically "-22.891996181150216, -43.127254512695345", "-22.86529776201615, -43.09548266210936" works my script if put on a variable does not work
– Fabio Henrique
more can not stay only in the first position
– Fabio Henrique
this values comes from the bank , the question is why manually goes and the variable does not
– Fabio Henrique