can the value of a numeric variable that comes in an array be converted, as a numeric value?

0

I have a number value that comes from an array,

$valorusuario = $request->valorusuario;

Is it an x and y number, when I see it with dd () "1" appears, is it possible to convert this variable to a numeric value?

It's just that something funny happens to me

/**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function selectord(Request $request)
    {

        $valorusuario = $request->valorusuario;
        $int = (int)$valorusuario;

        $numero = 1;
       
     
        $consultarea=usuarios::where('user_id', $numero)->paginate(2);
        $usuariosOpciones=usuarios::pluck('usuario_ad', 'user_id')->unique();
        return view('usuario.consultareas',compact('consultarea','usuariosOpciones'));
      
    }

in this method if I use the variable $ number the paid is perfect, but if I use the variable to which I made the conversion, load the first page but do not load the rest, I do not understand why the mess.

    
asked by zereft 13.11.2018 в 01:31
source

3 answers

1

It has ever happened to me that I have problems for PHP to take the variable as non-numeric.

In your case I would do the following, using the PHp functions that are for these topics:

    if(!is_int($int)){
        $int = intval($int);
    }

These will castrate the variables to the data type you need.

I hope it serves you.

    
answered by 13.11.2018 в 03:57
1

The answer is to handle a

$usuarios->appends(['valoruno'=>$valoruno, 'valordos'=>$valordos]);
    
answered by 15.11.2018 в 02:35
0

For special cases in which you want to convert, you can do it in the following way:

$valorusuario = $request->valorusuario;
$int = (int)$valorusuario; //para un valor entero
$float = (float)$valorusuario; //para un valor float

In any case, in most cases it is not necessary, since PHP will do the conversion automatically. This is part of the PHP data manipulation .

    
answered by 13.11.2018 в 02:26