3
I’m taking a value from a multiselect and sending it via ajax:
Assuming the value of multiselect is:
["1","2","3"] // é esse valor que está sendo enviado (value do multiselect)
After rescuing this value in the php file you received from ajax, how could I blow up that value just to pick up the numbers?
foreach
for an array or this ai is a string?– rray
Have you tested
$arr = json_decode('["1","2","3"]');
how do you want to use these numbers? note that these numbers are strings...– Sergio
So rray, I’m using a multiselect and when I do: $("#multiselect"). val() it returns it to me. In this case there are several values selected at once and sent via ajax. I would like to separate these values to use it in a foreach
– DiChrist
Yes I managed to make it work here, but how can I get it according to the amount sent? Because putting the values manually there worked, but the values will be sent via ajax. I get this value like this:
$valor = $_POST['valor']
, and then have to do it– DiChrist
forehead with
$arr = json_decode($valor);
. That’s how it works? Otherwisevar_dump($valor);
?– Sergio
then, it gave the error Invalid argument supplied for foreach() in C: xampp htdocs Matriculas index322.php on line 55 and var_dump is null
– DiChrist
Remember to pass true as json_decode’s second argument otherwise it returns an object
– rray