Sol Sol - 2 months ago 8
PHP Question

How can you build object oriented arrays in PHP?

There has to be a way to make

params2
work like
params1
. I figured both turn into an array, but I believe the
params1
is an object oriented array, which is causing my issue. How do you build
params2
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
$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