I am trying to generate the array structure as coding style so it can be used for further development for that purpose i have used following:
function convertArray($string)
{
$finalString = var_export($string, true);
return stripslashes($finalString);
}
It worked fine but the problem is that it adds the additional quotes to the start and end of the value how can i remove these quotes.
Example generated string is as follows:
array (
'foo' => 'array('foo','bar','baz')',
'bar' => 'array('foo','bar')',
'baz' => 'array('foo','bar')',
);
The string i need is:
array (
'foo' => array('foo','bar','baz'),
'bar' => array('foo','bar'),
'baz' => array('foo','bar'),
);
UPDATE
Here is how i create my array:
foreach( $attributes as $attrib )
{
if( $attrib->primary_key == '1' )
$column[$attrib->name] = array("'$attrib->type'", "'$attrib->max_length'", '\'pk\'');
else
$column[$attrib->name] = array("'$attrib->type'", "'$attrib->max_length'");
$string[$attrib->name] = 'array('.implode(',', $column[$attrib->name]).')';
}
after processing from this loop the final array sent to the above function to convert it into my desired form/
$string
exactly that you passed in function? – Kalpesh Mehta yesterday