Hi, hopefully this is an easy one for somone.. i've been pulling my hair out though..
I am creating an array of values which needs to be then passed to a function.
Everything works when I create it like this:
$myarray = array('value1'=>2,'value1'=>1,'value1'=>2,'value1'=>1);
However as i don't know how many elements there will be I, I am building a text string comtaining the values first inside a loop. so for each iteration of the loop I do this:
$arraystring = $arraystring."'".$field1name."'".'=>'.$field2name.',';
Then I remove the last comma and add a prefix:
$finalarraystring = 'array('.substr($arraystringstring,'',-1).')';
So effectivly I end up with a string called $finalarraystring which equals something like:
array('value1'=>2,'value1'=>1,'value1'=>2,'value1'=>1);
So what I am trying to do is to then create my array using this text string, but of course it is not working as it thinks I am trying to assign a string to my array.
I am trying
$array = $finalarraystring;
$array = '$finalarraystring';
$array = "$finalarraystring";
but nothings works. help!