Remove Orange Result Quotes 5.4

Asked

Viewed 434 times

1

I’m getting a result via Request in the Laravel thus: "2,1", I need to remove double quotes of the result, because when I enter as parameter in the query the whereIn understands as a string instead of a array and returns only 1 result instead of all.

  • 1

    post the full code !

2 answers

1


If text comes that elements are separated by comma, use explode to create a array of each element and then you need a array whole use array_map that will apply the function intval in each element of array:

Code

<?php

    $str = "2,1";

    $str = array_map(function($value){
        return intval($value);
    }, explode(",", $str));

Exit:

array(2) { [0]=> int(2) [1]=> int(1) }    

for check the result ONLINE.

References

0

Use the function explode of PHP:

$string = "2,1";
$array = explode(",", $string);

the result will be:

Array
(
    [0] => 2
    [1] => 1
)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.