Get the column type by the input PHP

92 Views Asked by At

So I have a question. I am currently looking at RedBeanPHP and I like how they can create tables, in development, on the fly and then freeze the schema for production.

I am looking to do something simmilar. Now what Im curious about is if PHP community has built anything where I can do:

$someClass->someFunction('string'); // Gives me back string as the column type.

Or:

$someClass->someFunction(99.0); // Gives me back double

and so on.

Does anything like this exist? I have tried searching and found nothing but you never know. Is there anything built into PHP to do this? I know theres various functions to see if bool, if string and so on, but that doesn't cover all the database column types.

Any help is appreciated

1

There are 1 best solutions below

0
On

Execute your variable inside var_dump($varhere); and it will display what it is. You can do a simple query to ASSOC Array, and then run a for each loop with an var_dump($var); and it will print what it is...

$a = array(1, 2, array("a", "b", "c"));
var_dump($a);

will out put the following

array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  array(3) {
    [0]=>
    string(1) "a"
    [1]=>
    string(1) "b"
    [2]=>
    string(1) "c"
  }
}

Same with

<?php

$b = 3.1;
$c = true;
var_dump($b, $c);

?>

will dump out

float(3.1)
bool(true)

I recommend you look at PHP Manual - var_dump()