Sol Sol - 10 months ago 41
PHP Question

How can you build object oriented arrays in PHP?

There has to be a way to make

work like
. I figured both turn into an array, but I believe the
is an object oriented array, which is causing my issue. How do you build
in an object oriented way?

$params1= array(
'column1' => $variable1,
'column2' => $variable2

$params2[":column1"] = $variable1;
$params2[":column2"] = $variable2;

To clarify my question:

I tried
$params2[":column1"] => $variable1;
and got errors, so is there another way to make an associate array this way?

Answer Source
$params = array(
   'column1' => $variable1,
   'column2' => $variable2

is equal to:

$params["column1"] = $variable1;   
$params["column2"] = $variable2;

but there is another option:

$params = (object) array(
     'column1' => $column1, 
     'column2' => $column2

echo $params->column1;
echo $params->column2;

if this is what you are looking for.

Please see here for more informations about php arrays