Remove quotation marks from Laravel Result 5.4

1

I'm getting a result via Request in Laravel like this: "2.1", I need to remove the double quotation marks from the result, because when I enter as a parameter in the query the whereIn understands as string ao instead of a array and returns only 1 result instead of all.

    
asked by anonymous 02.10.2017 / 15:55

2 answers

1

If text comes up that elements are comma-separated, use explode to create a array of each element and then if you need a% of integer use array_map that will apply the intval function on each element of array :

Code

<?php

    $str = "2,1";

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

Output:

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

to check the ONLINE result .

02.10.2017 / 16:02
0

Use PHP's function :

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

the result will be:

Array
(
    [0] => 2
    [1] => 1
)
    
02.10.2017 / 16:01